Block total MS Explorer on website

Here is the script

    $IE6 = (ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE7 = (ereg('MSIE 7',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE8 = (ereg('MSIE 8',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE9 = (ereg('MSIE 9',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE10 = (ereg('MSIE 10',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE11 = (ereg('MSIE 11',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
    $IE12 = (ereg('MSIE 12',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
if (($IE6 == 1) || ($IE7 == 1) || ($IE8 == 1) || ($IE9 == 1) || ($IE10 == 1) || ($IE11 == 1) || ($IE12 == 1)) {
   echo "The website not work with MS Explorer, you can back with Chrome / Opera / FireFox";
} else { 
//here website content
}

6,7,8,9 and 10 it was block.
But the last version 11 was not blocked… need help to currect this.

Thanks

Do you think it is wise to block IE users from being able to use your website?

Why would you write it this way? Why not the following?

$IE = (ereg('MSIE',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
if ($IE) {
  //block it
}

I second this. Later versions of IE seem to be more inline with Chrome, Firefox and Opera. So why do you need to block them?

Because my website not show the good style with Explorer.

I found way (block all versions)

preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if(count($matches)<2){
  preg_match('/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
}

if (count($matches)>1){
  //Then we're using IE
  $version = $matches[1];

  switch(true){
    case ($version<=8):
      //IE 8 or under!
      break;

    case ($version==9 || $version==10):
      //IE9 & IE10!
      break;

    case ($version==11):
      //Version 11!
      break;

    default:
      //You get the idea
  }
}

That’s a poor excuse. IE has a good sized chunk of the market. If I saw a website that forced me to change browsers, I’d leave and find another website that will give me what I want.

Head over to the HTML and CSS category over here on these forums and we’ll patch up the website. Include a link to the problem site, say WHAT VERSIONS of IE have the specific problems, and we will work with you. Be descriptive when identifying problem areas.

2 Likes

If you search, inaddition to MSIE, for ‘Trident’ then you’ll grab your IE11. IE11 stopped using MSIE as a user agent string. Specifically ‘Trident/7.0’ for IE11, or you could just do

$msie = (ereg('MSIE',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
$trident = (ereg('Trident',$_SERVER['HTTP_USER_AGENT'])) ? true : false;
if (($msie ==1) || ($trident == 1)) {
  //block it
}

Building on what @cpradio said.

Edit: Somewhat ninja’d.

Also, I agree with the above - if the reason you’re blocking is style problems, it’d be probably better to fix the style problems :wink:

I’d leave and find another website that will give me what I want.

Unless of course, it was say, a website that you were forced to use for work that only accepted particular IE versions, and then we just must grit our teeth and use it, or figure out an elaborate workaround. Weird how that works. :smiley:

1 Like

I moved 3 posts to a new topic: Poor IE display issues

1 Like

perhaps if you were to update to get rid of long dead code then your site would work better with all browsers.

Anyway you shouldn’t be testing the useragentr as that can contain anything and a lot of people running fully compliant browsers have their useragent set to spoof IE because a lot of sites stupidly test for that browser and will not allow you in of you are NOT using it.

Recently, I’m actually finding I.E. playing nicer lately than Firefox, which for me is a little strange. However, I design for all browsers and periodically check from time to time to see how the website looks on a particular browser. The only one I really get lacks on is Safari. :smile:

I still have Safari on my Windows OS.
But as the Windows version of Safari is “dead” I’ve been thinking testing with it is pointless unless I do so from within a VM

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.