Php to get the user's browser version, php to get the browser version _ PHP Tutorial

Source: Internet
Author: User
Tags ereg
Php gets the user's browser version, and php gets the browser version. Php gets the user's browser version. This article describes how php gets the user's browser version. Share it with you for your reference. The specific analysis is as follows: php obtains the user's browser version, and php obtains the browser version.

This example describes how to obtain the user's browser version by using php. Share it with you for your reference. The specific analysis is as follows:

In php, we have a global variable $ _ SERVER ['http _ USER_AGENT ']; which can obtain all user information. we need to process it before determining the type of user browser, the following function can accurately code the user's browser version number.

The code is as follows:

Function getbrowse ()
{
$ Agent = $ _ server ['http _ user_agent '];
$ Browser = '';
$ Browserver = '';
$ Browser = array ('Lynx ', 'Mosaic', 'AOL ', 'Opera', 'Java', 'macweb', 'webexplorer ', 'omniweb ');
For ($ I = 0; $ I <= 7; $ I ++ ){
If (strpos ($ agent, $ browsers [$ I]) {
$ Browser = $ browsers [$ I];
$ Browserver = '';
}
}
If (ereg ('mozilla ', $ agent )&&! Ereg ('msie ', $ agent )){
$ Temp = explode (', $ agent );
$ Part = $ temp [0];
$ Temp = explode ('/', $ part );
$ Browserver = $ temp [1];
$ Temp = explode ('', $ browserver );
$ Browserver = $ temp [0];
$ Browserver = preg_replace ('/([d.] +)/', '\ 1', $ browserver );
$ Browserver = $ browserver;
$ Browser = 'Netscape Navigator ';
}
If (ereg ('mozilla ', $ agent) & ereg ('Opera', $ agent )){
$ Temp = explode (', $ agent );
$ Part = $ temp [1];
$ Temp = explode (')', $ part );
$ Browserver = $ temp [1];
$ Temp = explode ('', $ browserver );
$ Browserver = $ temp [2];
$ Browserver = preg_replace ('/([d.] +)/', '\ 1', $ browserver );
$ Browserver = $ browserver;
$ Browser = 'Opera ';
}
If (ereg ('mozilla ', $ agent) & ereg ('msie', $ agent )){
$ Temp = explode (', $ agent );
$ Part = $ temp [1];
$ Temp = explode (';', $ part );
$ Part = $ temp [1];
$ Temp = explode ('', $ part );
$ Browserver = $ temp [2];
$ Browserver = preg_replace ('/([d.] +)/', '\ 1', $ browserver );
$ Browserver = $ browserver;
$ Browser = 'Internet explorer ';
}
If ($ browser! = ''){
$ Browseinfo = $ browser. ''. $ browserver;
} Else {
$ Browseinfo = false;
}
Return $ browseinfo;
}
// Application method

// In ie
Echo getbrowse (); // internet explorer 6.0
// In firefox
Echo getbrowse (); // netscape navigator 5.0

I hope this article will help you with php programming.

Examples in this article describes how to obtain the user's browser version by using php. Share it with you for your reference. The specific analysis is as follows :...

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.