I have an include file that generates a few things based on a variable called $pageid (such as page title, heading, menu button, etc.) It's very handy, as it dynamically important portions of every page. Anyway, I've recently added another folder to my site, which is protected via .htaccess, and the include files don't seem to be noticing the variable coming from the new folder. I had to use this line of code just to get the new page to call on the include file: ini_set("include_path", "/includes"); PHP: Any ideas why $pageid isn't making it to the include file? Thanks, Peter
Sorry, here... Average, working page on the site. These pages are in the root directory, as is the include folder. The filepath is root/workingfile.php: <?php $pageid = "clients"; include "includes/header.inc.php"; ?> PHP: The code to a page in the protected folder. The filepath is root/protected/index.php. This file does not display the $pageid variable like the ones in the root do, however I receive no error message: <?php $pageid = "protected"; ini_set("include_path", "/includes"); include "http://www.monochromedia.com/includes/header.inc.php"; ?> PHP: One of the include files. The filepath is root/includes/header.inc.php. I have included code snippets (shown below) so you can see the function of the $pageid variable: <title>Monochromedia - Premium Web and Graphic Design | <?php if ($pageid != "faq"){ $pageid = ucfirst($pageid); } else if ($pageid == "faq"){ $pageid = "FAQ"; } echo $pageid; $pageid = strtolower($pageid); ?></title> PHP: <body id="<?php echo $pageid;?>"> <div id="container"> <div> <a href="index.html"><img src="http://www.monochromedia.com/images/logo.gif" alt="" /></a> </div> <div id="spacer"> <div id="main"> <div id="top"> <h1><?php echo $pageid;?></h1> PHP:
I assume you mean the problem is with this snippet of code: <?php $pageid = "protected"; ini_set("include_path", "/includes"); include "http://www.monochromedia.com/includes/header.inc.php"; ?> PHP: where header.inc.php cannot access the $pageid variable. 1) You do not need to set the include_path to go up a directory. 2) If you try and include a file using a URL wrapper, the include_path becomes irrelevant. 3) In most cases, including using a URL wrapper will only return the output of the included file - i.e. the script is executed and then that output is send back to the script from which it was called. For obvious security (and slightly less significant, load) issues, you don't want to use a URL and you definitely don't want your server to allow scripts included in this way to inherit the variable scope. Use a relative or absolute path, not a URL. So that should become: <?php $pageid = "protected"; include '../includes/header.inc.php'; ?> PHP:
Warning: main(../includes/header.inc.php) [function.main]: failed to open stream: No such file or directory in /home/username/public_html/protected/folder/file.html on line 3 Code (markup): Same goes for all included files...
Given the error message you got, your include should read <?php $pageid = "protected"; include '../../includes/header.inc.php'; ?> PHP: Since the relative paths are causing confusion, you could also use: <?php $pageid = "protected"; include '/home/username/public_html/includes/header.inc.php'; ?> PHP:
lemaitre, your first example didn't work, however the second went off without a hitch. Thanks for the help!