如果用户使用任何形式的 Internet Explorer,我想禁止他们使用我的网站?如果使用 IE,我如何编写一个 php 脚本将用户重定向到不同的页面?
谢谢
这应该可以解决服务器端的问题。
<?php
function ae_detect_ie()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}
[...]
if(ae_detect_ie())
header('Location:/my_IE_webpage.php');
?>
来源:http ://www.anyexample.com/programming/php/how_to_detect_internet_explorer_with_php.xml
您也可以使用 Javascript 在客户端执行此操作:
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
if(getInternetExplorerVersion() > 0)
window.location.href = "/my_IE_webpage.php";
来源: http: //msdn.microsoft.com/en-us/library/ms537509 (v=vs.85).aspx
编辑
或者使用Vulcan的解决方案(客户端也是):
<!--[if IE]> <script type="text/javascript"> window.location = "http://example.com"; </script> <![endif]-->
您可能会发现 JavaScript 比 PHP 更容易做到这一点。使用 JavaScript,您可以在 IE 条件语句中包含脚本,以便它仅在用户运行 IE 时运行。
<!--[if IE]>
<script type="text/javascript">
window.location = "http://example.com";
</script>
<![endif]-->