阻止我的PHP网站在Internet explorer浏览器上打开


Prevent my PHP website from opening up on Internet explorer Browser

我的网站上有一些jquery插件和HTML5在Internet Explorer浏览器上运行时出现问题。如果它们不起作用,就会影响我网站的功能。如果用户通过IE浏览器打开我的网站,我如何禁用我的网站打开?类似于为用户显示一条消息,称"此浏览器不支持该网站"

请帮助

检查以下变量的输出以检查用户代理

$_SERVER['HTTP_USER_AGENT']

只需检查用户代理即可。使用strpos

<?php
$browser =  'MSIE'; 
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($user_agent,$browser) !== false) { 
echo "The website is not supported on this browser";
}

或者使用preg_match

 <?php
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/i',$user_agent))
    {
        echo "The website is not supported on this browser";
    }

希望这能帮助您

这可能很明显,但你试过看Modernizr吗?(http://modernizr.com/)

Codeigniter有一个内置库:

$this->load->library('user_agent');
if($this->agent->is_browser('Internet Explorer') && $this->agent->version() < 9) // Internet explorer older than i.e 9
{
    redirect("forbidden"); //Redirect, load view, echo, whatever you want to do
}