我正在测试这段代码,但"hello"在每个浏览器中都显示出来。通常它应该只显示在MSIE中。
我忘了什么吗?
$usragent = $_SERVER['HTTP_USER_AGENT'];
echo $usragent;
if(
((strlen(strstr($usragent,"Firefox")) <= 0)) ||
((strlen(strstr($usragent,"Chrome")) <= 0)) ||
((strlen(strstr($usragent,"Safari")) <= 0))
)
{
echo "hello";
}
我建议使用 php 函数 strpos。例:
if (strpos($usragent,'MSIE') == true) {
echo 'hello';
}
要完成您的案例,请举例:
if (strpos($usragent,'Firefox') || strpos($usragent,'Chrome') || strpos($usragent,'Safari')) {
echo "hello";
}