Page 1 of 1

Determine the current page name?

Posted: Wed May 30, 2007 2:34 pm
by Johnnyjoe2000
I have what is probably a super basic question, but it is something I have never seemed to need to do before, and must not be using the right Key words with google.

I have a very simple menu. On the home page I don't want it to display "Home" but I do on all the other pages. Like wise I want "About Us" to display on all the pages but the About page.

So in short I need to do the following:

if not current page = "index.php" display home link;
if not current page = "about.php" display about link;

etc...

Any ideas on how to do this? I came across some examples in my google research, but they all were very complicated and lengthy for what seams should be a simple one line of code per link.

Posted: Wed May 30, 2007 2:44 pm
by superdezign
You could check $_SERVER['PHP_SELF'], but everyone here who's a better programmer than me will recommend against it.

A more sure way is to create a variable in every page called, like, $title, and set it to the title you want it to be. Then, check against it. Just be sure to set the variable on every page before you check.

Posted: Wed May 30, 2007 2:51 pm
by feyd
__FILE__ may be of interest.

Posted: Wed May 30, 2007 2:57 pm
by superdezign
feyd wrote:__FILE__ may be of interest.
I've always wondered what the alternative was. I wasn't aware that it was a constant, but changed for each page.

Posted: Wed May 30, 2007 3:10 pm
by RobertGonzalez
I use __FILE__ or $_SERVER['SCRIPT_FILENAME'] in conjunction with basename(). I stay away from all things $_SERVER['PHP_SELF'].

Posted: Wed May 30, 2007 3:13 pm
by superdezign
Everah wrote:I use __FILE__ or $_SERVER['SCRIPT_FILENAME'] in conjunction with basename(). I stay away from all things $_SERVER['PHP_SELF'].
All I ever remember you guys saying was
Everah wrote:stay away from all things $_SERVER['PHP_SELF'].
Then, I frantically searched Google for an alternative, and finally decided to just assume that I had to specify it.

Posted: Wed May 30, 2007 3:14 pm
by RobertGonzalez
I asked this exact same question about two and half years ago. feyd showed me the way and I haven't looked back since.

As for the PHP_SELF thing, do enough local tests on it trying to corrupt it, you'll see why most stay away from it.