disallow Internet explorer 6.0 browser from opening website?
I'm developing开发者_运维百科 a website that I want to disallow opening in IE 6.0 Browser for some security reasons. I know every browser has a unique header information which sent when we request webpage so can I block my website opening in IE 6.0 or any browser using javascript,php or using anything ?
For IE it's easy because Microsoft added special tags that you can detect what IE version. It's much more reliable than trying to use the User-Agent
header. Something like this should work (in the head of your HTML)
<!--[if lte IE 6]>
<meta http-equiv="refresh" content="0;url=http://yoursite.com/ie6_is_a_steaming_pile.html">
<[endif]-->
Obviously replace the link with your own site and probably something more tactful ;-)
<!--[if (gt IE 6)|!(IE)]><!--> <html> Entire website? </html> <!--<![endif]-->
Seriously though, you can use the IE conditional comments à la HTML5 Boilerplate:
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en-us" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en-us" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en-us" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en-us" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en-us" class="no-js"> <!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" >
<meta charset="utf-8">
...
you can use conditional comments like this.
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
an unmodified version of internet explorer 6 will run this code, other browser will not. however i don't know if this satisfies your security concern. everything can be faked.
you can also check the header information but its the same problem...
please tell us more about what you are trying to do here.
Some simple PHP that you can include on every page to catch MSIE users:
if(preg_match('/MSIE/i',$_SERVER['HTTP_USER_AGENT'])){
die('Your browser is not allowed');
}
There are many other more complicated and comprehensive ways you can accomplish this aswell.
Sure, check this out (CGI method, PHP method, JS method)
PHP:
<?php
if (eregi("MSIE",getenv("HTTP_USER_AGENT")) ||
eregi("Internet Explorer",getenv("HTTP_USER_AGENT"))) {
Header("Location: http://www.domain.com/ie_reject.html");
exit;
}
?>
JS:
<!--
if (navigator.appName == "Microsoft Internet Explorer") {
document.location = "http://www.domain.com/ie_reject.shtml";
} else {
document.location = "http://www.domain.com/realhomepage.html";
}
// -->
Update AND teach them a lesson at the same time:
http://ie6update.com/
Ok, so it doesn't block them completely out. But it might trick some of them from getting rid of the evil scourge known as IE6. Darn Microsoft!
If you really want to do this...
In PHP:
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE 6")) {
// exit or redirect or whatever...
exit();
}
I would say: DO IT RIGHT! Have a class dedicated to it, trace down all USER_AGENTS of all browsers and devices out there, create a database of them and integrate it to your working Session routine. Everytime user comes in, determine his User-agent information [type, name and version] and then pass the data to your Display routines which should determine what content and design templates to print. This way, you can build a web site which is SEO-friendly, user-friendly, tidy and easy to organize [=developer-friendly] - ALL IN ONE, which is a VERY RARE THING to stumble upon in todays Internet... So, DO IT RIGHT!
The real answer is: you can't. A certain UA in a header is too easy to spoof to use it for security reasons, and if somebody wants to use IE6 on an app that doesn't allow it, one could use a simple proxy to get it done, making the app think that it is IE8.
That said, you can easily get it done in PHP using the get_browser function.
See http://php.net/get_browser
精彩评论