note 65721 added to function.include

From: Date: Sat, 06 May 2006 15:00:38 +0000
Subject: note 65721 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-110698@lists.php.net to get a copy of this message
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! ---- Server IP: 194.153.94.11 Probable Submitter: 84.226.105.160 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- http://master.php.net/note/edit/65721 Del: integrated -- http://master.php.net/note/delete/65721/integrated Del: useless -- http://master.php.net/note/delete/65721/useless Del: bad code -- http://master.php.net/note/delete/65721/bad+code Del: spam -- http://master.php.net/note/delete/65721/spam Del: non-english -- http://master.php.net/note/delete/65721/non-english Del: in docs -- http://master.php.net/note/delete/65721/in+docs Del: other reasons-- http://master.php.net/note/delete/65721 Reject -- http://master.php.net/note/reject/65721 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110698) next »