This is a discussion on included file, directory depth within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I want to include a common menu in all of my sites pages. Calling the file from any page is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I want to include a common menu in all of my sites pages. Calling the file
from any page is easy enough, linking to menu.php, ../menu.php, or .../../menu.php depending on where the particular web page is stored. The problem is, using the same menu.php file with links to various pages on the site, the paths get broken. A page two levels down will give menu items linking to the deep-down directory, when really I want the menu links to point to the top directory. Is there a function that can somehow detect what directory level the calling file is at, so that I can program the php to include as many ../'s in the menu as necessary? Thanks. |
|
|||
|
"Steve Greenaway" <macfisto@engsoc.org> wrote in
news:EWgNd.78501$rd7.1495189@weber.videotron.net: > I want to include a common menu in all of my sites pages. Calling the > file from any page is easy enough, linking to menu.php, ../menu.php, > or ../../menu.php depending on where the particular web page is > stored. > > The problem is, using the same menu.php file with links to various > pages on the site, the paths get broken. A page two levels down will > give menu items linking to the deep-down directory, when really I want > the menu links to point to the top directory. The best solution here is probably to hard-code absolute links in the included menu file. Instead of e.g. <a href="feedback/index.php"> you'd want <a href="/feedback/index.php"> with the forward slash in front. That way the links will always point to the same place, regardless of where you are on the site. > Is there a function that can somehow detect what directory level the > calling file is at, so that I can program the php to include as many > ../'s in the menu as necessary? getcwd() can give you what you need to do this, or you can do a substr_count() and count the number of slashes in $_SERVER[REQUEST_URI]. hth -- Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg'); --------------------------|--------------------------------- <http://www.phplabs.com/> | PHP scripts, webmaster resources |
|
|||
|
Don't use relative paths, use absolute paths instead, eg.
/www/yourdomain/public_html/include/menu.php regards alex Steve Greenaway wrote: > I want to include a common menu in all of my sites pages. Calling the file > from any page is easy enough, linking to menu.php, ../menu.php, or > ../../menu.php depending on where the particular web page is stored. > > The problem is, using the same menu.php file with links to various pages on > the site, the paths get broken. A page two levels down will give menu items > linking to the deep-down directory, when really I want the menu links to > point to the top directory. > > Is there a function that can somehow detect what directory level the calling > file is at, so that I can program the php to include as many ../'s in the > menu as necessary? > > Thanks. > > |