DenHepLei Posted November 28, 2007 Share Posted November 28, 2007 Hi, I need some help with some code, I am trying to use different (dynamic) content based upon the choice in a simple menu, here is what I have so far (see below), it works fine as long as the include files (a.inc, b.inc, etc...) are in the root directory, what I want to do though is keep all the include files in a subdirectory called includes, I am not familiar enough with PHP to change the code to make this work. ## SNIP ## <a href="<?php echo $_SERVER['PHP_SELF'];?>?page=a">A</a> :: <a href="<?php echo $_SERVER['PHP_SELF'];?>?page=b">B</a> :: <a href="<?php echo $_SERVER['PHP_SELF'];?>?page=c">C</a> <!-- Begin Dynamic Content --> <?php // create an array of allowed pages $allowedPages = array('a', 'b', 'c'); // check if the page variable is set and check if it is the array of allowed pages if(isset($_GET['page']) && in_array($_GET['page'], $allowedPages)) { // first check that the file exists if(file_exists($_GET ['page'].'.inc')) { // If all is well, we include the file include_once($_GET ['page'].'.inc'); } else { // A little error message if the file does not exist echo 'Warning: file not found.'; } } // if somebody typed in an incorrect url else { // if things are not as they should be, we included the default page if(file_exists('index.inc')) { // include the default page include_once('index.inc'); } else { // if the default page is missing, we have a problem and it needs to be fixed. echo 'Warning: index.inc not found.'; } } ?> <!-- End Dynamic Content --> ## SNIP ## Any help greatly appreciated! - DenHepLei Quote Link to comment https://forums.phpfreaks.com/topic/79283-include-files-dynamic-content-from-subdirectory/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.