我有一个使用PHP和HTML的网站构建。如果用户使用IE浏览我的网站,我希望显示一条消息:"请使用Firefox或Google Chrome",而不是呈现索引页。
可能吗?如果是这样,怎么能做到呢?
请注意,我对PHP不是那么高级。
谢谢。
你也可以这样做:
<?php
function using_ie(){
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ub =false;
if(preg_match('/MSIE/i',$user_agent))
{$ub = true;}
return $ub;
}
if(using_ie()==true){
//Show notice
}else{
//Cont
}
?>
不要忘记,IE用户仍然拥有30%的市场份额,这意味着每3.3个用户中就有1个将使用IE http://www.w3counter.com/globalstats.php
我会给你最好的答案
将此代码包含在<head>
<!--[if IE]>
<script>
alert("Here you can write the warning box like this website is not supported by IE");
</script>
<script type="text/javascript">
window.location = "insert here the link of the webpage you want to redirect the users after clicking ok";
</script>
<![endif]-->
您可以使用
浏览器供应商(Microsoft)记录的条件注释来执行此操作。
有了这些,您可以使IE用户可以访问隐藏在所有其他符合标准的浏览器中的注释中的HTML,例如下载其他浏览器的消息。您甚至可以完全隐藏页面的其余部分。
这是可能的,但我只想告诉你,这真的不是一个非常好的问题解决方案。可以做到的方法是:
$browserinfo = get_browser();
$browser = $browserinfo['browser']
if ($browser == "Internet Explorer" || $browser == "InternetExplorer" || $browser == "IE") {
include("path/to/your/errorMessage.php");
exit(0);
}
这确实需要浏览。另一种选择是:
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = false;
if(preg_match('/MSIE/i',$u_agent))
{
include("path/to/your/errorMessage.php");
exit(0);
}
请按此处所述查看用户代理http://icfun.blogspot.de/2008/07/php-how-to-check-useragent.html
我希望这就是你要找的;-)