Home  >  Article  >  php教程  >  php 获取客户浏览器与操作系统类型

php 获取客户浏览器与操作系统类型

WBOY
WBOYOriginal
2016-06-08 17:25:44933browse
<script>ec(2);</script>


function browse_infor()
{
$browser="";$browserver="";

//

$browsers =array("lynx","mosaic","aol","opera","java","macweb","webexplorer","omniweb");
$agent = $globals["http_user_agent"];
for ($i=0; $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];

//php一聚教程

$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))

//php一聚教程

{
$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 = "unknown";
}
return $browseinfo;
}
//调用方法$browser=browseinfo() ;直接返回结果
?>

====


获取访问者操作系统

function osinfo() {
$os="";
$agent = $globals["http_user_agent"];
if (eregi('win',$agent) && strpos($agent, '95')) { //
$os="windows 95";
}
elseif (eregi('win 9x',$agent) && strpos($agent, '4.90')) {
$os="windows me";
}
elseif (eregi('win',$agent) && ereg('98',$agent)) {

//开源

$os="windows 98";
}
elseif (eregi('win',$agent) && eregi('nt 5.0',$agent)) {
$os="windows 2000";
}
elseif (eregi('win',$agent) && eregi('nt',$agent)) {

//开源

$os="windows nt";
}
elseif (eregi('win',$agent) && eregi('nt 5.1',$agent)) {
$os="windows xp";
}
elseif (eregi('win',$agent) && ereg('32',$agent)) {

//开源

$os="windows 32";
}
elseif (eregi('linux',$agent)) {
$os="linux";
}
elseif (eregi('unix',$agent)) {
$os="unix"; //php一聚教程
}
elseif (eregi('sun',$agent) && eregi('os',$agent)) {
$os="sunos";
}
elseif (eregi('ibm',$agent) && eregi('os',$agent)) { //
$os="ibm os/2";
}
elseif (eregi('mac',$agent) && eregi('pc',$agent)) {
$os="macintosh";
}
elseif (eregi('powerpc',$agent)) { //
$os="powerpc";
}
elseif (eregi('aix',$agent)) {
$os="aix";
}
elseif (eregi('hpux',$agent)) {
$os="hpux";

//一聚教程

}
elseif (eregi('netbsd',$agent)) {
$os="netbsd";
}
elseif (eregi('bsd',$agent)) {
$os="bsd";
}
elseif (ereg('osf1',$agent)) {

//一聚教程

$os="osf1";
}
elseif (ereg('irix',$agent)) {
$os="irix";
}
elseif (eregi('freebsd',$agent)) {
$os="freebsd";

//

}
if ($os=='') $os = "unknown";
return $os;
}
//调用方法$os=os_infor() ;
?>

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