-1

我正在测试这段代码,但每个浏览器中都会显示“你好”。通常它应该只显示在 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";
        }
4

1 回答 1

-1

我建议使用 php 函数 strpos。例子:

if (strpos($usragent,'MSIE') == true) {
    echo 'hello';
}

要完成您的案例,例如:

if (strpos($usragent,'Firefox') || strpos($usragent,'Chrome') || strpos($usragent,'Safari')) {
    echo "hello";
}
于 2013-10-13T19:37:13.530 回答