Phone Home

What is the easiest way - using PHP - to tell whether I am on my “Home Page” or not?!

I have an included PHP Header, and would like to put some code in which tells me - Yes/No - if I’m on the Home Page.

(The solution should work locally on my Laptop and Virtual Host as well as on my Test Site and my actual Website with a real domain name.)

Any ideas?


One option is to use a session variable to keep track of what page you are on.

Using my next-to-no-PHP knowledge, what I’d try is an if statement based on the current URL:

$uri = htmlspecialchars($_SERVER['REQUEST_URI']);

if ($uri == "") {

... do something ...} else {

... do something else ...}

(May need some refining, but maybe a start … EDIT: I guess you might have a bit of trouble with that in your local environment, though … o well …)

Would you not already know when you are on a certain page like the home page when you send the page to the user? I’m confused…

This depends a lot on how your site is set up.
Loose PHP files for each page? Using a CMS?


All of my pages are in PHP - even if some are mostly HTML.

I have an include “” that create a page’s… (Need more time?) Header!!!

All was fine until last weekend I learned about this cool “Gilder-Levin Image Replacement” technique. SOOOO… I need my included “” file to be intelligent enough to look at whatever page is including it and determine if it is the Home Page or another page.

If it is the Home Page, then I echo my “Gilder-Levin” code, else if it is any other page I display my normal Page Header.

I have 3 environments currently…

1.) Development on my Laptop using a Virtual Host


2.) A Test Website which displays in my Address Bar as…[URL=“”]

…but which shows up as this…[URL=“”]

…when I copy and paste what was in the Address Bar?! :-/

3.) And then my real website which uses mod rewrites and would be somewhere like here…


I need code that doesn’t care where my website is being hosted, and that is smart enough to determine if the page being served up is the Home Page or not?!

I had this code…

    <!-- Find Current Page Name -->
        $page = basename($_SERVER['REQUEST_URI']);
        echo '<p>$page = ' . $page . '</p>';
//            if ($page == '') {
//            if (($page == '/')||($page == '')||($page == 'index.php')){
            if (($page == '/')||($page == '')||($page == 'index.php')){
                $page = "index.php";
                echo '<p>You are on the Home Page.</p>';
                echo '<p>You are on Some Other Page.</p>';

…but because of the loopiness in #2 above - and a general uncertainty - I am not sure that my code scales very well?! :-/

Make sense?


P.S. Mods, how do I show URLs here but not have them go to other sites??

Wrap them in [noparse] tags.

How many pages are we talking about here? 10? 100? One gazillion?

If it’s just a small number, you could set a key before including your header, and then use that key in a switch statement to output the correct “Gilder-Levin” code.