开发者

PHP if($_SERVER["REQUEST_URI"] == '/') [closed]

开发者 https://www.devze.com 2023-04-10 10:32 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous开发者_开发百科, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous开发者_开发百科, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

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