included file, directory depth

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


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-06-2005
Steve Greenaway
 
Posts: n/a
Default included file, directory depth

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.


Reply With Quote
  #2 (permalink)  
Old 02-06-2005
Senator Jay Billington Bulworth
 
Posts: n/a
Default Re: included file, directory depth

"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
Reply With Quote
  #3 (permalink)  
Old 02-06-2005
Alex Kulikov
 
Posts: n/a
Default Re: included file, directory depth

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:25 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0