Proper syntax for conditions

Discussion in 'PHP' started by YugKoobe, Dec 19, 2005.

  1. #1
    I'm using the following code to display ads on certain pages, but can't seem to figure out the proper way of adding more than one page.

    
    <?php $page=basename($_SERVER['PHP_SELF']); ?> 
    
    <?php if ( $page == 'index.php' ) : ?>
    <!-- Adsense code here... -->
    <?php endif; ?>
    
    Code (markup):
    I tried the following, but had no success.

    
    <?php $page=basename($_SERVER['PHP_SELF']); ?> 
    
    <?php if ( $page == 'index.php' , 'myfiles.php' , 'browse.php' ) : ?>
    <!-- Adsense code here... -->
    <?php endif; ?>
    
    Code (markup):
    What would be the proper syntax to display Adsense on those pages?

    Thanks in advance.
     
    YugKoobe, Dec 19, 2005 IP
  2. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    easy btw thats weird lucking php code u have

    u need logical OR ||

    happy to help, dont forget to spread some reputation i need it :)

      <?php
    
          $page=basename($_SERVER['PHP_SELF']);
    
          if ( ($page == 'index.php') || ($page ==  'myfiles.php' ) || ( $page == 'browse.php' ) ){
    
          print '<!-- Adsense code here... -->';
    
          }
    
          ?> 
    PHP:
     
    cornelius, Dec 20, 2005 IP
  3. YugKoobe

    YugKoobe Well-Known Member

    Messages:
    301
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #3
    I'm not getting any errors, but the ads are now on every page. The reason for this code is to prevent Adsense from appearing on the registration page (which goes against their TOS).

    I'm using Uploader v6.1 if that makes any difference.
     
    YugKoobe, Dec 20, 2005 IP
  4. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sorry theres a bug in my code (its early morning here :))

    here try this

    <?php
    
    $page=basename($_SERVER['PHP_SELF']);
    
    if ( ($page == 'index.php') || ($page ==  'myfiles.php' ) || ( $page == 'browse.php' ) ){
    
    print '<!-- Adsense code here... -->';
    
    }
    ?>
    PHP:
     
    cornelius, Dec 20, 2005 IP
    YugKoobe likes this.
  5. YugKoobe

    YugKoobe Well-Known Member

    Messages:
    301
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Awsome, works like a charm. Almost 6am here, time to logoff :)

    Thanks cornelius.
     
    YugKoobe, Dec 20, 2005 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    28,827
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #6
    A minor variation that I use because the page list can get lengthy
    <?php
      $page=basename($_SERVER['PHP_SELF']);
      $noAds = array('register.php','signup.php'); //etc
      if ( !in_array( $page, $noAds) ){
      print '<!-- Adsense code here... -->';
     }
     ?> 
    PHP:
     
    sarahk, Dec 20, 2005 IP
  7. YugKoobe

    YugKoobe Well-Known Member

    Messages:
    301
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #7
    Good point Sarah, I'll give it a shot tonight.

    Thanks for the help!
     
    YugKoobe, Dec 20, 2005 IP
  8. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm a bit clueless when it comes to PHP. Would you be able to use this in HTML code as well (perhaps using a PHP include) or how would one go about using the code.

    Any help appreciated.
     
    Crusader, Mar 26, 2006 IP