#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    I wish to execute a block of code if the browser is Netscape and another block of code if the browser is Internet Explorer by using PHP. How can i do that?
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    $HTTP_USER_AGENT stores the name of the browser being used.

    For Netscape 4.73 it's something like this:
    Mozilla/4.73 [en] (Win98; U)

    So you'd want to search for "ozilla" for Netscape (might start with M or m) and "MSIE" for Microsoft...

    $browser = $HTTP_USER_AGENT;
    if (strstr($browser,"ozilla")
    {
    echo "You're using Netscape";
    include("netscape_version.html");
    }
    elseif (strstr($browser,"MSIE")
    {
    echo "You're using MSIE";
    include("msie_version.html");
    }
    else
    {
    echo "I dont know what you're using...";
    include("plain_version.html");
    }

    Hopefully that gives you some ideas...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Newark, DE, USA
    Posts
    39
    Rep Power
    14
    unfortunately the user agent string for IE is

    Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)

    or something very similar. They abuse the use of "Mozilla" so scripts like yours will break. You'll have to look for MSIE before you look for Mozilla to make sure you catch IE browsers.

    ------------------
    ~Chris
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    Thanks for pointing that out...I haven't used $HTTP_USER_AGENT before...

    ---John Holmes...

Similar Threads

  1. mod_auth_mysql & php login check ?
    By yhcmarc in forum PHP Development
    Replies: 1
    Last Post: February 16th, 2004, 01:25 AM
  2. kids browser creation...
    By itd_network in forum Hire A Programmer
    Replies: 0
    Last Post: February 15th, 2004, 11:23 AM
  3. PHP auth system, need some help pls
    By dogbreath1974 in forum PHP Development
    Replies: 3
    Last Post: February 10th, 2004, 06:33 AM
  4. dynamically created check boxes
    By wduffee in forum PHP Development
    Replies: 3
    Last Post: February 3rd, 2004, 01:10 PM
  5. How to check how many users are connected in php
    By chandar in forum PHP Development
    Replies: 1
    Last Post: January 29th, 2004, 09:30 AM

IMN logo majestic logo threadwatch logo seochat tools logo