Two ifs Statements.

Discussion in 'PHP' started by soapbath, May 29, 2005.

  1. #1
    Okey, im a newbie when it comes to PHP, most of the time I hire people to do it for me,

            <?php 
    if (strstr($_SERVER["HTTP_USER_AGENT"], "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; DimensionBrowserV2.A; .NET CLR 1.1.4322)")) {
    ?>
                <?php 
    } else { 
    ?>
       You are not up-to-date, please make sure you update now!</strong><br>
            Download: <a href="DimensionBrowser.exe">HERE</a> (EXE)<br>
            Download: <a href="DimensionBrowser.zip">HERE</a> (ZIP) <br>
            Download: <a href="DimensionBrowser.rar">HERE</a> (RAR)</span>
              <?php 
    } 
    ?>
        
    PHP:
    That checks if the user is using the latest dimension browser version, but I need to add to ifs like

            <?php 
    if (strstr($_SERVER["HTTP_USER_AGENT"], "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; DimensionBrowserV2.A; .NET CLR 1.1.4322)")) {
    
    if (strstr($_SERVER["HTTP_USER_AGENT"], "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; DimensionBrowserV2.A; .NET CLR 1.1.4322 Alexa Toolbar)")) {
    ?>
                <?php 
    } else { 
    ?>
       You are not up-to-date, please make sure you update now!</strong><br>
            Download: <a href="DimensionBrowser.exe">HERE</a> (EXE)<br>
            Download: <a href="DimensionBrowser.zip">HERE</a> (ZIP) <br>
            Download: <a href="DimensionBrowser.rar">HERE</a> (RAR)</span>
              <?php 
    } 
    ?>
        
    PHP:
     
    soapbath, May 29, 2005 IP
  2. Penfold

    Penfold Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use a logical 'or' in your if() statement. (Two pipe symbols are a way of writing OR)
    if($this == true || $that == true){
    	do something;
    }
    Code (markup):
    Alternatively you can use an elseif:

    if(){
    	do something;
    }
    elseif(){
    	do this instead;
    }
    else{
    	do this;
    }
    Code (markup):
    It does appear, however, there is a simpler way to solve your problem. You only wish to check if a user is using "DimensionBrowserV2.A", yes?

    If so, you can use the quicker strpos() (http://uk.php.net/manual/en/function.strpos.php) function:
    <?php
    if (strpos($_SERVER["HTTP_USER_AGENT"], "DimensionBrowserV2.A") === false) {
    ?>
       You are not up-to-date, please make sure you update now!</strong><br>
            Download: <a href="DimensionBrowser.exe">HERE</a> (EXE)<br>
            Download: <a href="DimensionBrowser.zip">HERE</a> (ZIP) <br>
            Download: <a href="DimensionBrowser.rar">HERE</a> (RAR)</span>
    <?php
    }
    ?> 
    Code (markup):
    As the user-agent string can vary quite wildly, this will handle users on other operating systems (Win 2k for example) and with other browser features :).
     
    Penfold, May 29, 2005 IP
  3. soapbath

    soapbath Peon

    Messages:
    909
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Penfold, I want your babies... ;). Thanks for the help it works wonders.
     
    soapbath, May 29, 2005 IP
  4. Penfold

    Penfold Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hehe, no problem :).
     
    Penfold, May 29, 2005 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    {lol} A simple PHP question and she wants your babies. Not bad. heh
     
    digitalpoint, May 29, 2005 IP