Page 1 of 1

include/require not displaying included file

Posted: Mon Aug 23, 2004 8:42 am
by dashifen
Greetings,

I'm working with PHP 4.3.3 and I've begun to rework an older website for PHP. One of the things we did with the old site was include a header and footer file at the top and bottom of files which controlled much of the look and layout of the page. Now, with PHP, however, it's not working.

The files are included; if you "view source" on the page, all of the HTML contained within the header and footer pages are included in the source output. However, the screen does not show this HTML. I don't understand what else I need to do to get this working. Any ideas?

Info:
PHP v4.3.3
Windows Server 2003 with IIS6

Posted: Mon Aug 23, 2004 8:47 am
by JayBird
Seem like a problem with your HTML.

Can you post what your php code looks like and also what the HTML output is from the view source.

Mark

Posted: Mon Aug 23, 2004 9:41 am
by dashifen
Bech100 wrote:Seem like a problem with your HTML.

Can you post what your php code looks like and also what the HTML output is from the view source.

Mark
I actually found out it's because I was using absolute paths in the html (starting with a / to refer to the document root of the web page). This is because the header and footer can be included at many different "levels" within the site so using relative linking would constantly need a differing amount of "../" to refer to the correct "level." I'm going to get in touch with the net admin over this, but if you have a solution, let me know and I can let him now.

Thanks!

Posted: Mon Aug 23, 2004 10:06 am
by markl999
Just add the path to the header and footer to your include_path either in php.ini, a .htaccess, using ini_set or set_include_path() if your version supports it. Then you can just include/require header.php from anywhere without needing to specify levels/paths

Posted: Mon Aug 23, 2004 10:49 am
by dashifen
markl999 wrote:Just add the path to the header and footer to your include_path either in php.ini, a .htaccess, using ini_set or set_include_path() if your version supports it. Then you can just include/require header.php from anywhere without needing to specify levels/paths
The issue isn't including the file; the file is included. However, after the file's included, the web page doesn't display all elements of the header/footer.

For example, if the following image were in the header it would load:

<img src="http://mywebsite/media/images/someimage.gif">

But this image would not load:

<img src="/media/images/someimage.gif">

The latter format is all bu necessary because I'm working on a development machine and I'd rather not have to deal with global find/replace to move from the dev. machine to the live machine.

The need for the latter format rather than using relative links is because the included file can be included from within a number of depths within the website. Consider this, if index.php includes the file, then the link to the graphics would this: "media/images/someimage.gif." But, a page within the content folder loads an image, the path would be "../media/images/someimage.gif." As a result, the document root path (beginning with /) should load the correct image from any depth within the site without requiring zero or more "../" prepended to the img tag's src attribute.

I could (relatively) easily code a php function that would count the number of /'s in the URL ($_SERVER['PHP_SELF']) and from that extract the necessary numebr of ../'s to prepend to the links within the header, footer, and any other includes of this nature, but I'd rather not such measures if the server can be configured to make this happen.

After working on the problem for the last two hours or so, I'm becoming convinced that this is an issue with IIS 6 and not with PHP, so I don't know if you all can help, but if anyone has any ideas, let me know. I've also posted on other boards specific to IIS.

Thanks!

Posted: Mon Aug 23, 2004 11:00 am
by dashifen
In fact, I'm now certain that it's not a PHP issue because I can alter the img link to begin with a "/" in index.php outside of the included files and it still doesn't work.

Posted: Mon Aug 23, 2004 12:16 pm
by John Cartwright
Is the included file in the same directory as the file including it?

Posted: Mon Aug 23, 2004 1:05 pm
by dashifen
Phenom wrote:Is the included file in the same directory as the file including it?
No. Hence the need for a linking method that will work from any depth within the web site.