开发者

Do not show on default page

开发者 https://www.devze.com 2023-03-17 02:58 出处:网络
I have a header which is showed on all my pages. In that header I have a banner. Is there a way to not show that banner on the root page as well as other 开发者_StackOverflow社区pages?

I have a header which is showed on all my pages. In that header I have a banner.

Is there a way to not show that banner on the root page as well as other 开发者_StackOverflow社区pages?

Something like this:

If (!Root OR !/test.php) {
    BANNER
}


function pageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

if (pageName() != 'index.php' && pageName() != 'test.php') {
  BANER
}


I suggest you to test the value of $_SERVER['REQUEST_URI'], which gives you the URI.

Something like that:

if ($_SERVER['REQUEST_URI'] != '/test.php') {
  //Display your banner
}


Try this:

   <?php
       $url = $_SERVER["REQUEST_URI"];
       if ($url !== '/') && ($url  !== '/test.php') {
          banner();
       }
    ?>


What about the magic constant __FILE__ to determine which PHP-Script is currently running?

But you could also use the $_SERVER['SCRIPT_NAME']-variable to just get the Scripts name (without the full path).

0

精彩评论

暂无评论...
验证码 换一张
取 消