search

Home  >  Q&A  >  body text

Ask a question about $_SERVER['HTTP_USER_AGENT']

echo $_SERVER['HTTP_USER_AGENT'];

The output is:

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0 .3497.92 Safari/537.36

I just want to know which browser sent it. Why are they all listed?

Yang_SirYang_Sir1956 days ago1387

reply all(2)I'll reply

  • 王林

    王林2019-08-21 11:13:02

    <?php
    if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 8.0"))  
    echo "Internet Explorer 8.0";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 7.0"))  
    echo "Internet Explorer 7.0";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE 6.0"))  
    echo "Internet Explorer 6.0";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/3"))  
    echo "Firefox 3";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox/2"))  
    echo "Firefox 2";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome"))  
    echo "Google Chrome";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Safari"))  
    echo "Safari";  
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Opera"))  
    echo "Opera";  
    else echo $_SERVER["HTTP_USER_AGENT"];  
    ?>

    That’s it.

    reply
    0
  • Yang_Sir

    But here there is "Chrome" and "Safari", and there is also Edge when opening it with Edge. In this judgment statement, which condition is written before the one comes out, which is definitely wrong. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134".

    Yang_Sir · 2019-08-21 11:27:42
  • Cancelreply