Home > Backend Development > PHP Tutorial > How to get the user's browser version in php, get the browser version in php_PHP tutorial

How to get the user's browser version in php, get the browser version in php_PHP tutorial

WBOY
Release: 2016-07-13 10:10:23
Original
838 people have browsed it

How to get the user browser version in php, get the browser version in php

The example in this article describes how to obtain the user's browser version in PHP. Share it with everyone for your reference. The specific analysis is as follows:

In php, we have a global variable $_SERVER['HTTP_USER_AGENT']; which can obtain all the user's information. We need to process it before we can determine the type of user's browser. The following function can accurately browse the user's information. Server version code.

Copy code 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 be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/936799.htmlTechArticleHow to get the user browser version with php, get the browser version with php. This article explains how to get the user browser version with php method. Share it with everyone for your reference. The specific analysis is as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template