Php obtains the browser type of the visitor's browser page.
The method is as follows:
Check your agent string, which is part of the HTTP request sent by the browser. Use $_SERVER['HTTP_USER_AGENT']
Obtain the agent string.
For example:
<?php echo $_SERVER['HTTP_USER_AGENT'];?>
It may be printed like this:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Encapsulated as a function:
Function my_get_browser () {if (empty ($ _ SERVER ['HTTP _ USER_AGENT ']) {return 'Robot! ';} If (false = strpos ($ _ SERVER ['HTTP _ USER_AGENT'], 'msi ')) & (strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'trigger ')! = FALSE) {return 'Internet Explorer 11.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'msie 10.0') {return 'Internet Explorer 10.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'msie 9.0') {return 'Internet Explorer 9.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'msie 8.0') {return 'Internet Explorer 8.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'msie 7.0') {return 'Internet Explorer 7.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'msie 6.0') {return 'Internet Explorer 6.0 ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'edge') {return 'edge ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'Firefox') {return 'Firefox ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'chrome') {return 'chrome ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'safari') {return 'safari ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'Opera') {return 'Opera ';} if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], '360se') {return '360se';} // browser if (false! = Strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'micromessage') {return 'micromessage' ;}>}
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.