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

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

WBOY
Release: 2016-07-13 09:59:27
Original
897 people have browsed it

How to get user browser version in php

This article mainly introduces how to get user browser version in php. You can use $_SERVER['HTTP_USER_AGENT'] to get user information. , is a very practical skill, friends who need it can refer to it

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.

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/975890.htmlTechArticleHow to get the user browser version in php. This article mainly introduces the method of getting the user browser version in php. Using $_SERVER['HTTP_USER_AGENT'] to obtain user information is a very practical technique...
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