Using PHP to identify the folder the page is in?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sampage
Forum Newbie
Posts: 22
Joined: Sat Mar 18, 2006 6:17 pm

Using PHP to identify the folder the page is in?

Post by sampage »

Sorry this is a long post, in short: Is it possible to get PHP to identify the folder a page sits in?

I have a header.php page which has tabs on it as a menu system, this page is loaded into all other PHP pages when they load. When a person goes to the different areas (i.e. Information, Search) the tab for the area needs to update so that it is highligted.

Rather than having the coding on every page and setting the tabs to update manually, does anyone know of a way to get the master page, which the header is loaded into, to be able to detect which folder it sits in (i.e. /information/ or /search/ ) which I can then use to update the header page with, reflecting which tab should be selected.

The trouble with putting the header page into each page seperatly, rather than loading from an external document, is that when i make changes I have to update every page on the site!!!

Any advice would be really appreciated, sorry for the long post!
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

dirname($_SERVER['PHP_SELF']);
sampage
Forum Newbie
Posts: 22
Joined: Sat Mar 18, 2006 6:17 pm

Post by sampage »

Thank you for your reply, perfect!

Say I have this code:

Code: Select all

$folder = dirname($_SERVER['PHP_SELF']);
Which actually equalled /en/people/information/group/ - what would be a method of searching the directory tree for "people"?

I have used PHP searches before, but not for some time - sorry to go back to basics!
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I'm not sure what you mean by 'search'

Are you just trying to see if the current page is a child of the 'people' directory?
sampage
Forum Newbie
Posts: 22
Joined: Sat Mar 18, 2006 6:17 pm

Post by sampage »

Yes thats right, would it inolve a LIKE search, although I only know how to do this when looking through a database for records.

I need something along the lines off:

When $folder contains 'people' $mainfolder="1"

//

When $folder contains 'information' $mainfolder="2"

And so forth, thanks for your time on this one!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

strpos() or an explode() followed by an array_search():idea:
Post Reply