SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting a browser using PHP

    Hi,

    I was wondering what is the best way of detecting a users Browser using PHP.

    What I would like to do is send slightly different pages for Netscape than for IE (also possibly for older browsers etc).

    So does anyone know the best way of going about it ? I believe there is a variable $HTTP_USER_AGENT (or something like that) - is this the thing I'm looking for ?

    If it is does anyone have a list of variables it will produce for common browsers so I can work out how to use them to differentiate between browsers and serve pages accordingly.

    Many thanks in advance.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think there is a list per se. But here are a few.

    All on windows
    Code:
    IE 6
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) 
    
    Netcape 4.7
    Mozilla/4.78 [en] (Windows NT 5.0; U) 
    
    Opera 5
    Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 5.12  [en]
    
    Netscape 3.04
    Mozilla/3.04 (WinNT; I) 
    
    Netscape 6.1
    Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks Freddie.

    So what I could do is test for strings such as "IE", "Netscape", "Opera" etc then if 'true' server the pages as appropriate. Can you see any problems with this, and are there any other 'common' browsers I should look for ?

    If a search engine comes along do you know what sort of variable they would send (if any). Will they send something such as "IE" or "Netscape" or something different?

    Many thanks in advance.

  4. #4
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They send stuff like "AltaVista PageCrawler." It's best to do something like:

    if ($IE_is_in_string) { // internet explorer

    } else { // netscape, opera, and all others

    }

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many Thanks - I guess the variable $HTTP_USER_AGENT is the correct one to use - correct ? or is there another more appropriate ?

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use $HTTP_USER_AGENT

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Denmark
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    One more little resource for you

    I had some excellent success with modifying a script found on www.phpbuilder.com
    You'll find it under articles/html/brrowser detection and css generation

    Good luck
    Nick Wilson
    www.explodingnet.com
    Small business websites

  8. #8
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the above it is very helpful.

    I was looking through my log stats and I was wondering if anyone could explain a few thinks to me: -

    Below is a listing of the top 40 browsers that use my site - They all appear to be MSIE. Can anyone explain what Mozilla is (which is part of almost all string for user agent)?

    Also there is no 'Netscape' agents listed in the top 40, would anyone know a reason for this ? When I look at my graph for 'browser summary' Netscape or Netscape 'copmatible' accounts for about 5% so it seems strange - any ideas ?


    1 77222 8.89% Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
    2 61113 7.04% Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)
    3 59564 6.86% Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
    4 55570 6.40% Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
    5 50874 5.86% Mozilla/4.0 (compatible; MSIE 5.5; 1276680: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
    856479: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
    810490: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)
    792281: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
    721279: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
    682171: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
    535119: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
    442960: Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)
    355906: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95)
    306692: PHP/4.0.4pl1
    303371: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
    284965: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
    235115: Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
    234775: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)
    215181: Mozilla/3.01 (compatible
    180344: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
    176275: Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
    175174: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
    157494: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; fs_ie5_04_2000i)
    128558: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)
    120015: MSProxy/2.0
    76345: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)
    65906: Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0)
    64897: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTinternet V8.4)
    64420: Mozilla/4.0 (compatible; MSIE 5.0; AOL 6.0; Windows 98; DigExt)
    63643: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    60924: Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)
    53200: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; compaq)
    51231: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)
    49812: Mozilla/4.0 (compatible; MSIE 5.5; AOL 6.0; Windows 98; Win 9x 4.90)
    45312: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; CGC 0.14)
    41186: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; BT Internet)
    39577: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; BTinternet CD v7.0)
    38778: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt; Hotbar 2.0)
    37147: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
    33045: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt; sureseeker.com)
    32017: Googlebot/2.1 (+http://www.googlebot.com/bot.html)
    31186: Mozilla/4.0 (compatible; MSIE 4.5; Mac_PowerPC)
    31100: Mozilla/4.0 (compatible; MSIE 5.01; Windows 98; fs_ie5_04_2000i)
    30750: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Supplied by blueyonder)

  9. #9
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unless your viewing the entire list, it may not show users browsing with netscape. remember, thats the Top 40, not all.
    netscape users are dwindling.
    Defender's Designs
    I'm Getting Married!

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

  10. #10
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeh, I suppose that may be so.

    Anyone know the answer to my Mozilla question - its probably a dumb one but I'd like to know.

    Cheers

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Denmark
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    long back when......

    I believe it comes from the days of yawn when netcape ruled and internet explorer need to tell folks it was compatible and should be treated as such,
    For Opera you'll see somthing similar to all that with Opera tagged on the end.
    Nick Wilson
    www.explodingnet.com
    Small business websites

  12. #12
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it just means its mozilla compatible.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  13. #13
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks.

    Does Anyone have a more complete list than that kindly supplied by Freddie so that I can cover all situations/browsers.

    Thanks

  14. #14
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whatever happened to the I.E. ghost "Mosiac"?
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  15. #15
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have an idea of what MSProxy/2.0 is a result of - it ranks fairly high in my list of top browsers. Any ideas what this is generated from ?


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
  •