Recently, the project requires some different processing based on the browser type of the user, so I studied a little bit about how to use php to determine the browser type, the following article describes how to obtain the browser type of a visitor's browser page in php. For more information, see. 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 '] to obtain the agent string information.
For example:
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.
For more articles about the browser type used by php visitors to browse the page, refer to the PHP Chinese website!