我有一個在localhost上的Internet Explorer版本8上工作的代碼。它在服務器(Filezilla)上不起作用。同樣的代碼不能在localhost上的Internet Explorer版本10上運行(filezilla)。我想要解決方案,以便它可以在本地主機上以及server.Code上的IE版本10上運行。代碼如下。爲什麼我的代碼在localhost上的Internet Explorer版本8上不是在服務器上,而是在Internet Explorer版本10上工作
<?php
function get_user_browser() {
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if (preg_match('/MSIE/i', $u_agent)) {
$ub = "ie";
} elseif (preg_match('/Firefox/i', $u_agent)) {
$ub = "firefox";
} elseif (preg_match('/Safari/i', $u_agent)) {
$ub = "safari";
} elseif (preg_match('/Chrome/i', $u_agent)) {
$ub = "chrome";
} elseif (preg_match('/Flock/i', $u_agent)) {
$ub = "flock";
} elseif (preg_match('/Opera/i', $u_agent)) {
$ub = "opera";
}
return $ub;
}
//echo get_user_browser();
$browser = get_user_browser();
if ($browser == 'ie') {
echo "<script>alert('Your Browser is not compatible, Please Update the version')</script>";
echo "<script>window.open('www.google.com','_self')</script>";
}
?>
它工作正常,在我的瀏覽 –
你不能只是這樣做與https://modernizr.com/前端? – Chris
像@Chris建議,請做這個前端。更好的是,你可以只用CSS來完成。檢測IE是一件微不足道的事情,不需要做後端。 –