PHP get user Browser version Code _php tutorial

Source: Internet
Author: User
PHP get the user browser version code in PHP we have a global variable $_server[' http_user_agent '], can get all the information of the user, we have to be processed to determine the type of user browser, the following function can be accurate user browser version number code.

PHP Tutorial Get user Browser version code
In PHP we have a global variable $_server[' http_user_agent '], can get all the information of the user, we have to be processed to determine the type of user browser, the following function can be accurate user browser version number code.

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.html www.bkjia.com true http://www.bkjia.com/PHPjc/444900.html techarticle PHP Get the user browser version code in PHP we have a global variable $_server[' http_user_agent '], can get all the user information, we have to process to determine 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.