Php to obtain the user's browser version. Php: how to obtain the user's browser version this article mainly introduces how to obtain the user's browser version by using php. you can use $ _ SERVER [HTTP_USER_AGENT] to obtain user information, it is a very practical technique for php to obtain the user's browser version.
This article describes how to obtain the user's browser version in php. it is a very practical technique to use $ _ SERVER ['http _ USER_AGENT '] to obtain user information, for more information, see
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.
This article describes how to use php to obtain the user's browser version. you can use $ _ SERVER ['http _ USER_AGENT '] to obtain user information. this is a very practical technique...