1

This is my home.php:

require('header.php');

This is my header.php

if (basename(__FILE__) == "home.php"){
        echo "you are on home.php"; 
} else {
        echo "you are not on home.php";
}

When I now open the URL www.mypage.com/home.php I see the text you are not on home.php

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • `__FILE__` is a macro which will always return the filename in which it is defined - i.e. in this case, it will always equal `"header.php"`. Answers to this question may solve your problem: http://stackoverflow.com/questions/6768793/get-the-full-url-in-php – Tom Lord Jun 22 '16 at 08:17
  • @TomLord Yes, but this gives me the full URL, this is not what I need. I need only the filename – peace_love Jun 22 '16 at 08:20

1 Answers1

2

Try something like this

<?php
    $explode = explode("/", $_SERVER['REQUEST_URI']);
    $explode = explode("?", $explode[count($explode)-1]);

    echo $explode[0];
b0ne
  • 653
  • 3
  • 10