How do I code this PHP?

Discussion in 'Programming' started by AJO, Dec 20, 2008.

  1. #1
    Goal: To have my banner only display on the main page, otherwise display another image.

    I'll achieve this through different CSS ID's, but am wondering what the proper PHP would be to check the page and apply the ID? I can't seem to find this on Google.

    Thank you for your help
     
    AJO, Dec 20, 2008 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    do something like this :
    <?php
    $page = $_SERVER['PHP_SELF'];
    if($page == "./products.php") {
    print "<div for this or img src";
    }elseif($page == "./contact.php"){
    print "<div for contact";
    }
    ?>
    etc.
     
    crivion, Dec 20, 2008 IP
  3. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've never noticed $_SERVER['PHP_SELF'] returning the script name with a period at the start. This would work just as well if not better:
    <?php
      if (substr(strtolower($_SERVER['PHP_SELF']),'products.php')>0) {
        echo 'display banner for products page';
      } else {
        echo 'display other banners';
      }
    ?>
    PHP:
     
    Yesideez, Dec 20, 2008 IP
  4. AJO

    AJO Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So <div id="

    <?php
    if (substr(strtolower($_SERVER['PHP_SELF']),'/store/cart.php?m=content&page=16')>0) {
    echo 'homepagebanner';
    } else {
    echo 'otherbanner';
    }
    ?>

    ">

    Would work? Thanks
     
    AJO, Dec 21, 2008 IP
  5. AJO

    AJO Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    AJO, Dec 26, 2008 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    <?php
    
    $url = 'http://www.domain.com/store/cart.php?m=content&page=1';
    $strip_www = true;
    
    /* All lowercase upto the end of the hostname, then natural casing */
    define( 'CURRENT_URI', strtolower('http' . ((isset($_SERVER['HTTPS']) and $_SERVER['HTTPS']) ? 's' : '') . '://' . (($strip_www) ? str_replace('www.', '', strtolower($_SERVER['HTTP_HOST'])) : $_SERVER['HTTP_HOST'])) . ((isset($_SERVER['SERVER_PORT']) and $_SERVER['SERVER_PORT'] != 80) ? $_SERVER['SERVER_PORT'] : '') . $_SERVER['SCRIPT_NAME'] . ((isset($_SERVER['QUERY_STRING']) and strlen($_SERVER['QUERY_STRING']) > 0) ? '?' . $_SERVER['QUERY_STRING'] : '') );
    
    if ( $url == CURRENT_URI )
        echo 'It\'s the URL you entered!';
    else
        echo 'It\'s not.';
    
    
    PHP:
     
    Danltn, Dec 26, 2008 IP