Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parsing PHP string for browser detection

    I am writing a script to apply a different stylesheet to a page depending on whether the user is using IE or Mozilla.

    1st part is fairly simple - browser is detected from the environment variable HTTP_USER_AGENT. This returns (for example):

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

    I want to be able to split up this string so that only the browser type variable (i.e. the MSIE 6.0 in this case) is left. From that I can re-direct as appropriate

    Any suggestions?
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whenever you need something, and you think that there must have been lotts of other people that ever needed this, then a google will always turn up some ready made code. Like

    http://www.phpbb.com/phpBB/viewtopic...153&highlight=

    but i'm sure there will be many other here http://www.google.be/search?q=php+br...-8&hl=nl&meta=

    and probably in the PHP usermanual http://be.php.net/function.get-browser
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Remember that if you do server-side browser detection you need to set Private caching so that proxy-servers don't cache it. And also that server-side detection is unreliable, because browsers can mis-identify themselves.
    Last edited by brothercake; 03-24-2004 at 09:27 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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