|
Posted by Tyrone Slothrop on 10/24/05 15:39
On 24 Oct 2005 02:40:41 -0700, "Pete" <petesouthwest@hotmail.com>
wrote:
>Hi
>
>i have a page hmenu.htm that acts like a menu bar; containing links to
>other pages on my site ie:
><a href="../CMS/sysReq.htm">
><a href="../index.php"> etc
>
>I am includeing this in all of the pages on my site using:
><?php include("includepages/hmenu.htm"); ?>
>
>The pages that use the include are in various levels up to about 4
>subdirectories deep.
>
>However, my problem is that as the links are relative, on many of the
>pages showing the included file, the links dont work as I am not going
>far enough back up the path structure. ie ../index.php on some pages
>needs to be ../../index.php etc.
>
>Looking on the net I found suggestions that I might have a hmenu.htm
>for each folder level, but that seems to negate the advantage of using
>include!
>
>I ahve also found suggestions that I need to put absolute links in ie
>www.mydomain.com/index.php. Is that the only way?
>
>Any help appreciated.
>Thanks
>Pete
You can evaluate the depth of the current page relative to the
document root using $_SERVER['PHP_SELF'] then pass that to the include
file. For example, you can count the number of forward slashes in
PHP_SELF and deduct one to determine the number "../" you need. Of
course it gets a bit complicated since you either have to have an
absolute link to the include or call from a function to pass the var.
However, it would probably be just as easy to use absolute links.
Navigation:
[Reply to this message]
|