note 65721 deleted from function.include by bjori
| From: | bjori@php.net | Date: | Sat, 06 May 2006 16:16:41 +0000 |
| Subject: | note 65721 deleted from function.include by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-110703@lists.php.net to get a copy of this message | ||
Note Submitter: vamp at vampworld dot net
Reason: bad code
----
A simple way to make a dynamic include system is the following. It returns an error if the requested
file could not be found.
<?php
if(isset($_GET['site'])) //Change site to whatever you want
{
$dir = 'includes/'; //Change it to your folder with the include files, but
don't forget the "/" at the end!!
$file= $_GET['site'].'.php'; //Or .inc.php or .phtml or whatever
$include= $dir.$file;
if(!file_exists($include))
{
echo 'The requested page could not be found.';
}
else
{
include($include);
}
}//End of if(isset($_GET['site']))
else
{
include('default.php'); //Or just place echo "hello"; there; this lines are just
default, if the user comes to the page
}
?>
Well, I know it's not the best include "system". But with this script fragment as a
base, you can make it alot more dynamic. E.g. you add a time(); line, and then insert it to a
Database to analyze where the people go and when.
Hope it was useful!