PHP get the user browser version of the method, PHP get Browser version _php tutorial

Source: Internet
Author: User
Tags ereg

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: ...

  • 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.