Page 1 of 1

Do included files inherit paths or use their own?

Posted: Sat Jan 29, 2005 2:55 am
by steedvlx
This question is either so basic that I should know the answer, or else the answer is buried somewhere that I can't seem to locate.

I am trying to use a common_header.php and common_footer.php for the pages in my site. However, when I try to do this, image links for main pages in different subdirectories are broken.

I have tried to fix this by setting a variable at the beginning of the main file that establishes the offset to the image directory from the loaded file's location (ie $relative_offset = '../'; ) and changing all links to reflect that path. (ie img src=<?php echo($relative_offset . "images/image.gif")?>;

This doesn't get the job done for some reason.

Either A) The included file does not 'see' volatile variables that are set outside of it
or B) The paths are getting messed up in ways that I don't understand.

CAn anyone point me to a resolution of this problem?

I want to;
Keep all included files in //root/includes
Keep the BODY sections in their own subdirectories (arranged by menu selection)
AND still be able to use a single header file (also footer file) for every page on the site.

Any help is appreciated

Posted: Sat Jan 29, 2005 3:01 am
by wwwapu
Have you tried this http://www.w3.org/TR/html4/struct/links.html#edef-BASE ?

Defining base uri should help.

Posted: Sat Jan 29, 2005 10:39 am
by steedvlx
Thanks for that link. It looks like a working solution.

I will have to play with it however, since the manual doesn't specify examples I can work out mentally for my case. I'm not sure if the BASE directive should be in the main file or the included file, or both.

I'll try it out until I understand how it works. Funny that I wasn't looking for HTML to be the solution for the problem. I was looking all over for a PHP solution... go figure eh?

Thanks Again

Posted: Sat Jan 29, 2005 11:51 am
by wwwapu
BASE goes to your pages head section. So I suppose the right place for it could be in common_header. Assuming that common_header has doctype declarations title, meta and such...

Almost forgot. Include files should inherit the base, because php.exe renders pages as one file. some.inc becomes a part of rendered page.php.

Posted: Sat Jan 29, 2005 11:54 am
by steedvlx
OK, I think that got it.

A puzzling thing about the BASE directive is that it is persistent. Once it is declared in an 'include' it remains in effect for the rest of the document.

I tried to declare the BASE in the main 'index' file to the site root and in the include to the correct includes directory path.

While the include file's relative links resolved correctly, the main file's image links then resolved two levels off. (persistant BASE directive)

I corrected this by using the aforementioned $img_offset_path = "../../" to effectively cancel out the effects of the BASE directive for these images.

As a noob cum intermediate coder, this whole thing results in output code that I'm afraid to even reveal to the gen-pub. The noob mantra applies here... "But sir, it works."

page is here http://www.chirowebjapan.com/index_test.php

Thanks again for the help. Hopefully this will help my pages load faster.

Posted: Sat Jan 29, 2005 11:58 am
by steedvlx
wwwapu wrote: Almost forgot. Include files should inherit the base, because php.exe renders pages as one file. some.inc becomes a part of rendered page.php.
Heh he. I guess we were both posting our last comments at the same time. :)

Thanks for all the good info

Posted: Sat Jan 29, 2005 12:31 pm
by wwwapu
There still seems to be some problems with HTML formatting. There is multiple pages one after one first one I saw was about at line 117 and the second at 406 and so on. There will be difficulties with the multiple <body> and <head> sections. All User Agents (browsers) won't work with that.

Am I supposed to see pictures? I don't.

The included files don't have to be "whole" pages. They can be partial pages with only some formatting. Like "table there, table here".

Posted: Sat Jan 29, 2005 9:09 pm
by steedvlx
Thanks for pointing that out. I just got too tired to clean things up last night.

Today, I moved the javascripts and consolidated the styles section into the main load-file. And, then stripped all the extra HEAD and BODY tags out of the includes to clean it up a bit. Now, I just have to take care of the rest of the site pages.

I think it is reasonably 'acceptable' now. I have tested in IE, NS, Opera, and FireFox with good results.

If you are still not seeing the images, then I have a more serious problem that I can't see from my location. Please let me know if the page doesn't load them. It should look exactly like http://www.chirowebjapan.com/index.php

As a special thanks to all in the group; This website would not even exist without the great information and help that I have received in this group over the last two years.
THANKS

Posted: Sun Jan 30, 2005 4:38 am
by wwwapu
Sorry, my mistake. :oops:
I have been testing Kerio personal firewall. There is a default setting "Enable web filtering" which blocks small .gifs as if they were advertisement.
All images show just fine now on both index.php and index_test.php.

And I might add that it looks very nice.

Posted: Sun Jan 30, 2005 7:24 am
by steedvlx
Thank you. For both checking out that problem and for the compliment. :D