PHP get the user browser version of the method, PHP get Browser version
The example in this article describes how PHP gets the user browser version. Share to everyone for your reference. The specific analysis is as follows:
In PHP we have a global variable $_server[' http_user_agent '], we can get all the information of the user, we have to be processed to determine what kind of user browser, the following function can be accurate user browser version number code.
Copy CodeThe 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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/936799.html www.bkjia.com true http://www.bkjia.com/PHPjc/936799.html techarticle PHP Get the user browser version of the method, PHP get Browser version of this article describes how PHP gets the user browser version of the method. Share to everyone for your reference. The specific analysis is as follows: ...