SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $http_user_agent values

    Using $http_user_agent in a conditional statement depending upon what client is being used, what are the possible values I should use? For example:
    PHP Code:
    <?php
    if ($http_user_agent == "Internet Explorer" or "Netscape 6" or "Opera 5")
    {
         echo(
    "do this");
         exit();
    }
    else
    {
         echo(
    "do this");
         exit();
    }
    ?>
    Are those the appropriate values for the user clients; should they be something else? Thanks.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got a question, does an if (...) work like that or should it be:

    PHP Code:
    if ($HTTP_USER_AGENT == "Internet Explorer" || $HTTP_USER_AGENT == "Netscape 6" $HTTP_USER_AGENT == "Opera 5"
    ?? i don't know, just wondering.

    but no, those user agent string aren't anything like the actual values. for example this is mine in IE 6:

    Code:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    so you'll have to use more of a regular expression to find out the browser.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I think it depends on what application you creat. Here is an example at phpbuilder
    here:http://www.phpbuilder.com/columns/ti...21.php3?page=2

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dr: I've noticed that when i use just an or without the variable, it doesn't work.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <?

    if ((!strstr(getenv('HTTP_USER_AGENT'), 'MSIE' OR 'Gecko'))) {
    //For IE and NS 6
    } elseif ((strstr (getenv('HTTP_USER_AGENT'), 'Opera'))) {
    //For Opera
    } else {
    //For NS 5 and under
    }

    ?>
    That what i used and it works great.
    Save Some Money, and Grab some Hot Deals!
    www.DealSpree.com

  6. #6
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I'll give all of those a try.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  7. #7
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The whole strstr(getenv... etc doesn't like me.
    PHP Code:
    <?php
    if ($HTTP_USER_AGENT == "MSIE" or "Opera")
    {
            echo(
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n" .
            
    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd\">\n");
    }
    elseif (
    $HTTP_USER_AGENT == "Gecko" or "Netscape6/6")
    {
            echo(
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
    }
    else
    {
            include(
    "nostyle.php");
            exit();
    }
    ?>
    What is wrong with this? Opera and IE seem to work fine, but Netscape6/Mozilla keep including the content from the first if statement instead of the following elseif.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  8. #8
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try

    if (($HTTP_USER_AGENT == "MSIE") or
    ($HTTP_USER_AGENT == "Opera"))


    ($HTTP_USER_AGENT == "MSIE") can be true or false, but
    (or "Opera") is true all the time. So
    F or T is T
    T or T is T
    Therefore the first if statement is true all the time.
    Anyone, correct me if I'm wrong

  9. #9
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay -- so I simply need to separate those? I'll give that a go. Thanks.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •