2012-04-20 94 views
0

我有一个使用PHP和HTML构建的网站。如果用户使用IE浏览我的网站,我想显示一条消息:“请使用Firefox或Google Chrome”,而不是呈现索引页。强制用户使用Chrome/FireFox而不是IE

可能吗?如果是这样怎么办?

请注意我不是那种先进的PHP。

谢谢。

+1

这是可能的,但很可能不令人满意的,除非你正在创建一个银行网站与用户仍然有IE6。 – Lekensteyn 2012-04-20 11:34:48

+2

你为什么想这样做 – Toto 2012-04-20 11:35:39

+2

@ M42 - 猜猜Sarah喜欢疏远用户。 – 2012-04-20 11:36:34

回答

2

你也可以做这样的:

<?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用户仍然拥有的市场份额含义1 30%的用户为3.3将使用IE http://www.w3counter.com/globalstats.php

+0

我会将该功能放在网站标题中吗? – 2012-04-20 12:31:39

+0

下降到[19.17%](https://www.netmarketshare.com/browser-market-share.aspx?qprid=0&qpcustomd=0) – toddmo 2017-03-26 17:28:09

1

这是可能的,但我只是想告诉你,这真的不是一个很好的解决问题的办法。它可以做到的方式是:

$browserinfo = get_browser(); 
$browser = $browserinfo['browser'] 

if ($browser == "Internet Explorer" || $browser == "InternetExplorer" || $browser == "IE") { 
    include("path/to/your/errorMessage.php"); 
    exit(0); 
} 

这确实需要browscap。另一种选择是:

$u_agent = $_SERVER['HTTP_USER_AGENT']; 
$ub = false; 

if(preg_match('/MSIE/i',$u_agent)) 
{ 
    include("path/to/your/errorMessage.php"); 
    exit(0); 
} 
+0

你应该提到这取决于browscap – mishu 2012-04-20 11:41:46

1

我会给你最好的答案

包括<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]-->

相关问题