PHP gets the browser type of the visitor browse page

Source: Internet
Author: User
Methods are as follows

Checks the user's agent string, which is part of the HTTP request sent by the browser. Use $_server[' http_user_agent '] to get the AGENT string information.

Like what:

<?php echo $_server[' http_user_agent '];? >

It is possible to print out this:

mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Encapsulated into functions:

function My_get_browser () {if (Empty ($_server[' http_user_agent ')) {return ' robot! '; if (false = = Strpos ($_server[' http_user_agent ', ' MSIE ')) && (Strpos ($_server[' http_user_agent '), ' Trident ' !==false) {return ' Internet Explorer 11.0 ';} if (False!==strpos ($_server[' http_user_agent '], ' MSIE 10.0 ') {return ' in ternet 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 ')) {RET Urn ' 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 ';} }

Summarize

The above is the entire content of this article, I hope that the content of this article on everyone's study or work can bring certain help, if there is doubt you can message exchange.

Related Article

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.