SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check if Browser IE6 or Lower

    I'm trying to put together a PHP script that checks if the browser is IE6 or lower.

    I tested my IE7 with HTTP_USER_Agent and got this response:

    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

    What would the response be for IE6 or lower? Need to somehow setup a script that performs a different action if browser turns out being IE and version 6 or lower.

    Thanks
    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  2. #2
    SitePoint Zealot adam.jimenez's Avatar
    Join Date
    May 2009
    Location
    Ware, UK
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it something you could do with conditional comments instead?
    http://www.positioniseverything.net/...s/cc-plus.html

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, i thought about that. But it's not a change of CSS but an actual <img> src.

    Ryan
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Code:
    For IE 6 <!--[if IE 6]><img ...><![endif]-->
    Not for IE 6 <!--[if !IE 6]><!--><img ...><!--<![endif]-->
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Wizard
    Join Date
    Oct 2004
    Location
    Newport Beach
    Posts
    1,761
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked perfect. Thanks
    Upcoming Movies - Movie News. Updated Daily.
    Movie Trailers - Awesome trailer site. Nuff said.

  6. #6
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Code:
    For IE 6 <!--[if IE 6]><img ...><![endif]-->
    Not for IE 6 <!--[if !IE 6]><!--><img ...><!--<![endif]-->
    The question was how to do it in PHP, not how to do it using Microsoft's proprietary non-standards compliant BS. This is one way (as with most coding problems there are multiple ways to skin a cat).

    PHP Code:
    <?php
    if (stristr('MSIE'$_SERVER['HTTP_USER_AGENT'])) {
      
    // Some breed of Internet Exploder...
      
    if (stristr('MSIE 7.0'$_SERVER['HTTP_USER_AGENT'])) {  
      {
        
    // IE 7, also IE 8 when in broken pages mode
        // (it lies about its user agent in that mode -- joy)
      
    } else if if (stristr('MSIE 8.0'$_SERVER['HTTP_USER_AGENT'])) {
        
    // IE 8
      
    } else {
        
    // IE 6 or earlier falls here, though you can branch all up
        // and down the line if you feel like it here.
      
    }
    }
    ?>

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    The question was how to do it in PHP...
    Doing it with PHP is unreliable. Using the conditional comments works all the time every time and only ever target IE.

    not how to do it using Microsoft's proprietary non-standards compliant BS.
    Actually it is perfectly standards compliant, it is just an HTML comment. Now what IE may do with this comment maybe proprietary, but nonetheless it is fully compliant with the standards. Everything between <!-- and --> is ignored making CCs compliant.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can't do it with PHP since the only thing PHP has access to to identify a browser is the useragent which is a free format user enterable field.

    Both IE and Firefox allow the useragent to be set to anything at all while Opera and Safari allow the useragent to be changed to identify the browser as IE or Firefox.

    How do you know if the useragent says "Blue Mud is the BEST Mud" whether the browser is IE5, IE8, or Firefox 4? How do you know if the useragent says "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;..." whether the browser is IE, Opera, or Safari? Answer to both is that you have no way to tell.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    1 Thread(s)
    If people coddled old video game systems with large market shares the way Internet Explorer gets coddled the Atari 2600 would still be the defacto home console. If the net is ever to have forward progress IE must get with the times or get lost.

  10. #10
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by felgall View Post
    You can't do it with PHP since the only thing PHP has access to to identify a browser is the useragent which is a free format user enterable field.
    Tell me, when is the last time you met a user savvy enough to DO that who was also stupid enough to run IE given it's vast array of exploits and hacker vulnerabilities?

  11. #11
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    Tell me, when is the last time you met a user savvy enough to DO that who was also stupid enough to run IE given it's vast array of exploits and hacker vulnerabilities?
    While I agree that in the case of IE, those people who spoof headers will be quite savvy, the problem with what you mentioned is that plenty of old IE users are not stupid, they are well aware of the fact that IE6 for example is ridden with flaws and bugs... unfortunately they refuse (or cannot) upgrade, not through stupidity but through vanity (the love of the GUI).

  12. #12
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    It doesn't take a savvy user to change the user agent, it can be done via third-party applications a lot of times its security applications. It can even be done by proxies.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  13. #13
    SitePoint Zealot adam.jimenez's Avatar
    Join Date
    May 2009
    Location
    Ware, UK
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fact is that conditional comments are always guaranteed to work - so what's the problem?

  14. #14
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    While I agree that in the case of IE, those people who spoof headers will be quite savvy, the problem with what you mentioned is that plenty of old IE users are not stupid, they are well aware of the fact that IE6 for example is ridden with flaws and bugs... unfortunately they refuse (or cannot) upgrade, not through stupidity but through vanity (the love of the GUI).
    Good post. Mustn't forget users who are restricted by work policies from upgrading as well though.
    Even a stopped clock tells the right time twice a day.


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
  •