Php: Getting user's browser version code _ PHP Tutorial

Source: Internet
Author: User
Php obtains the user's browser version code. Php obtains the user's browser version code. in php, we have a global variable $ _ SERVER [HTTP_USER_AGENT]. this variable can obtain all user information, after processing, we can determine that the user's browser is php to get the user's browser version code. in php, we have a global variable $ _ SERVER ['http _ USER_AGENT ']; all user information can be obtained. we can determine the type of user browser only after processing. the following function can accurately display the user's browser version number code.

Php Tutorial to get the user's browser version code
In php, we have a global variable $ _ server ['http _ user_agent ']; which can obtain all user information. we need to process it to determine the type of user browser, the following functions can accurately show the version number of your browser.

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


Http://www.bkjia.com/PHPjc/444900.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444900.htmlTechArticlephp get user browser version code in php we have a global variable $ _ SERVER ['http _ USER_AGENT ']; can get all user information, we have to deal with it before we can judge whether the user's browser is...

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.