Do not show on default page
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).
精彩评论