Jump to content

Include files dynamic content from subdirectory


DenHepLei

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.