include/require not displaying included file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

include/require not displaying included file

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

Post 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!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

Post 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!
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Is the included file in the same directory as the file including it?
dashifen
Forum Commoner
Posts: 35
Joined: Thu Feb 05, 2004 9:53 pm
Location: Champaign - Urbana, IL

Post 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.
Post Reply