PHP Includes on several different levels of a site


#1

I am using PHP Includes on several different levels of a site. I have got all of the left nav bars to link correctly by coding the different levels for each category and including the leftnev specific to the category in the file. Here is the problem. I am using headers and footer includes on every page. It seems that depending on the level parsed, the links think they live on that level and will not call the next page (i.e., home, etc.). I know there have to be a work around.

~b


#2

There’s quite a few work-arounds for dynamic linkage and path alteration methods, most of which are quite obvious using if() conditionals and adding “…/” strings to your paths. But one of the easiest things to do, thougn not particularly adventurous, is to make all your links literal and point to a full path.

<a href="<?php echo $_SERVER['HTTP_HOST']."/folder/file_etc.php; ?>">link

That way they will default to the site root every time when resolving the path. Like I say, it’s not a particularly efficient method, but if you’re wanting something short-term to fix the problem until you code a better work-around with some string handling and conditions, it might be useful.

p.s. another popular way is to get php to work out how deep into the site it is by counting the “/” signs in the current url ($PHP_SELF).