Block/Redirect IE6 users

This script may not be for everyone but it is pretty cool.

<?php

$ua = $_SERVER['HTTP_USER_AGENT'];

if (strpos($ua,'MSIE') != false && strpos($ua,'Opera') === false)
{
if (
strpos($ua,'Windows NT 5.2') != false)
{
if(
strpos($ua,'.NET CLR') === false) return;
}
if (
substr($ua,strpos($ua,'MSIE')+5,1) < 7)
{
header('Location: http://redirect.com');
}
}

?> 

That little snippet of PHP coding will redirect all IE6 users to a different page. This is perfect for designers who want the follow the trend of Open Addict and block all IE users from viewing their website. You can find out more about this code here. Also do not forget the opening and closing tags.

About these ads

28 thoughts on “Block/Redirect IE6 users

  1. Tim Wheatley

    This is great! I am not a fan of IE7…

    I use Vista, XP and the Mac OS (yes, I have the OSX installed on my PC) and obviously test everything I do with Vista+IE7, Vista+Firefox, Vista+Safari, XP+IE6, XP+Firefox, XP+Opera, OSX+Safari, OSX+Firefox and it’s only IE7 that screws everything up…

    Reply
  2. Tim Wheatley

    Yeah. As OSX is essentially a modified Linux, it’s a case of modifying it back again. Now that Mac uses Intel processors it’s also really easy to do.

    I first of all tested whether it’d work by setting it up on a Virtual Machine using this guide:

    http://asendure.wordpress.com/2006/10/01/osx86-how-to-install-mac-os-x-on-vmware-server-amd-64/

    (except I use the Intel drivers not the AMD drivers)

    …then once I knew I had hardware that supported it virtually, I just had to make myself a Journal formatted FAT32 partition and use Acronis Disk Director’s OS selector to select between the OS’s when I boot up. Works great.

    You can get modified drivers (usually modified Linux drivers) in the forums of this site:

    http://www.insanelymac.com/

    *

    I never really had any design issues with IE6, but IE7 seems to display things differently… I guess that’s just another bad thing about IE! Everyone has different issues – but we ALL have issues! :)

    Reply
  3. A.B.

    That’s nonsense. Just don’t care if your site works with IE and maybe tell them it’s their browser’s fault.

    Reply
  4. Brock

    I need to just point out that you code has some mistakes. There is an extra } on line 6. Also when you copy and paste this code you need to be careful your using the right ‘ because the ones copied from the page are wrong.

    $ua = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($ua,’MSIE’) != false && strpos($ua,’Opera’) === false)
    {
    if (strpos($ua,’Windows NT 5.2′) != false)
    { if(strpos($ua,’.NET CLR’) === false) return; }
    if (substr($ua,strpos($ua,’MSIE’)+5,1) < 7)
    {
    header(‘Location: http://redirect.com‘);
    }
    }

    Reply
  5. Ron

    What does this section do?

    if (strpos($ua,’Windows NT 5.2′) != false)
    { if(strpos($ua,’.NET CLR’) === false) return; }

    Don’t you just need to check if the $ua string returns ‘MSIE 6.0′ ?

    Reply
  6. :// Post author

    Windows 2000, Windows XP, and Windows Server 2003 are based on versions 5.0, 5.1, and 5.2 respectively of the NT kernel. Windows Vista is version 6.0, but it will be running IE7. So, it seems that a reasonable, albeit not foolproof, way of differentiating IE6 from browsers masquerading as it, would be to search for the version numbers of both the ‘MSIE’ and ‘Windows NT’ strings, and the presence of the ‘.NET CLR’ string.

    -http://lab.amanwithapencil.com/user_agent/

    Reply
  7. Kimberly

    Thank you for this code! After 10 hours of trying every Internet Explorer 6 png hack that I could find, iepngfix.htc, and receiving less than satisfactory results in my WordPress site – this was the absolute best solution.

    The corrected redirect is PERFECT.

    Reply
  8. Pingback: Tips on How to Stop or Slow Down a DDoS Attack | Gettin' Geek

  9. Skinny

    I agree with test.
    I paste this in at the very top of the code:

    <?php

    $ua = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($ua,’MSIE’) != false && strpos($ua,’Opera’) === false)
    {
    if (strpos($ua,’Windows NT 5.2′) != false)
    { if(strpos($ua,’.NET CLR’) === false) return; }
    if (substr($ua,strpos($ua,’MSIE’)+5,1)

    Messgae I get is:
    I get a parse error Unexpected T_STRING in mywebsite.com on line 6

    Reply
  10. Pingback: Developer Blog » Internet Explorer 6 Redirection

  11. Pingback: Blokere eller redirecte til anden side | iWANT.dk - Rå viden forklaret så det kan forstås

  12. Marco

    Got a question. This isn’t cloaking or anything right? I don’t want any SEO problems with this. Do let me know please (if not too late to ask :) )

    Reply
  13. get discount tire coupons

    Whats up are using WordPress for your blog
    platform? I’m new to the blog world but I’m trying to get started and set up my own.
    Do you require any coding knowledge to make your own blog?
    Any help would be really appreciated!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s