I administer two different PHP sites residing on two different servers, one running PHP as an Apache module and the other in CGI mode. Obviously the files on the CGI server must have the #!/usr/local/bin/php statement at the top and be executable whereas the Apache module site does not. Both sites are very similer in basic design concept and layout. They both use templates that format pages based on inherited varibales via URLs. For example the page "index.php" is the main template for the whole site which has a space between the header and footer areas that reads:
<? include "$page.php" ?>
When a user points to http://www.domain.com/index.php?page=products, they see the template page with all of the content from "products.php" properly formatted in the right place. Simply enough?
The CGI site has the #!/usr/local/bin/php statement at the top of the template page but not in the actual content pages because the content pages are included from the template page.
For organizational sake, I have named each content page the same name as the variable that is to be passed to the template (ie. "products.php", "contact.php", etc.).
With this desgin concept I have run into a problem with the PHP CGI site. When a user points directly to a content page (like "products.php" after entering a product name in my search engine) they see the content without all of the formatting (since the template had not been included). To fix this I just figured I would add some conditional logic at the top of each content page like this:
<?
if (!(isset ($page)))
{
$filename = strrchr ($PHP_SELF, '//');
$filename = substr ($filename, 1);
$ext = strrchr ($filename, '.');
$ext_length = strlen ($ext);
$filename = substr ($filename, 0, -$ext_length);
$page = $filename;
echo "
<head>
<meta http-equiv=\"refresh\" content=\"0; url=index.php?page=$page\">
</head>
?>
This code figures out what the $page variable is based on the name of the file ($filename minus the extention) and does an html redirect to the correct page. This all works fine on the Apache module site but on the CGI the content pages fail since they don't have the #!/usr/local/bin/php statement. If I add #!/usr/local/bin/php to each content page it will be echoed back to the browser since it it in the middle of the <body> tag.
I realize that a database is a more elegant way to handle this problem but that is not an option on either of the servers.
Any ideas?
thank you in advance.