PHP if($_SERVER["REQUEST_URI"] == '/') [closed]
I am trying to display a banner on the front page of my shopping cart, but not the rest of the pages on my site. I am using the code below, but it doesn't seem to be working correctly.
<?php
if ($_SERVER['REQUEST_URI'] == "/")
{
print '<img src=\"images/banner_2.jpg\">;
}
?>
This should work everywhere:
if (!isset($_SERVER['REQUEST_URI']) || ltrim($_SERVER['REQUEST_URI'],'/') === '') {
print '<img src="images/banner_2.jpg">';
}
Only issue is that if for whatever reason the HTTP server does not provide $_SERVER['REQUEST_URI']
, you will end up with a banner on every page.
精彩评论