前端之家收集整理的这篇文章主要介绍了
php 获取浏览器信息的简单示例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对
PHP获取访问者浏览器感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
<?
/**
* PHP获取访问者浏览器
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
function browse_infor()
{
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
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); $Part=$temp[1];
$temp =explode(")",$browserver);$browserver=$temp[2];
$browserver =preg_replace("/([d.]+)/",$browserver);
$browserver = " $browserver";
$browser = "Opera";
}
if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent))
{
$temp = explode("(",$Agent); $Part=$temp[1];
$temp = explode(";",$Part); $Part=$temp[1]; //开源OSPHP.COM.CN
$temp = explode(" ",$Part);$browserver=$temp[2];
$browserver =preg_replace("/([d.]+)/",$browserver);
$browserver = " $browserver";
$browser = "Internet Explorer";
}
if ($browser!="")
{
$browseinfo = "$browser$browserver";
}
else
{
$browseinfo = "Unknown";
}
return $browseinfo;
}
//调用方法$browser=browseinfo() ;直接返回结果
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528710.html