TheFilmGod Posted June 22, 2008 Share Posted June 22, 2008 I would like to require/include files from a subdirectory called "element" that is in my root directory. This is difficult because this is my custom 404 error page. Someone can try opening up any files in any made up directory and the server "thinks" its in that directory. For instance, if a user goes to mydomain.com/hello/yay/doesitwork.php, I need to include my files as "../../element" This code SHOULD work, but it only works for pages called at one directory up i.e. mydomain.com/directory/somefile.php <?php // Grab Address, i.e "/hello/yay/doesitwork.php" $address = $_SERVER['REQUEST_URI']; // Count how many backslashes exists, i.e 3 $count = substr_count("$address", "/"); // Subtract 1 / i.e. 3-1 = 2 $count--; // Create a repeated text string for more than 1 / i.e. ../../ $bslash = str_repeat("../", $count); // Define Unique Page Elements, this is the main thing! $element = "$bslash" . "element/"; // Require the Session Script require ($element.'session.php'); ?> Here is the code without as many comments. <?php // Grab Adress, count bslash, create address to root $address = $_SERVER['REQUEST_URI']; $count = substr_count("$address", "/"); $count--; $bslash = str_repeat("../", $count); // Define Unique Page Elements $element = "$bslash" . "element/"; $root = "$bslash"; // Require the Session Script require ($element.'session.php'); ?> Link to comment https://forums.phpfreaks.com/topic/111342-requireinclude-files/ Share on other sites More sharing options...
Bendude14 Posted June 22, 2008 Share Posted June 22, 2008 $element = $_SERVER['DOCUMENT_ROOT'].'/ try this Link to comment https://forums.phpfreaks.com/topic/111342-requireinclude-files/#findComment-571606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.