Php: obtain the browser type of the visitor's browser page _ php instance-PHP source code

Source: Internet
Author: User
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. 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']Obtain the agent string.

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.