您好,欢迎访问一九零五行业门户网

php获得客户端信息类

php取得客户端信息类
getlang(); //获取访客语言:简体中文、繁篦中文、english。 $obj->getbrowser(); //获取访客浏览器:msie、firefox、chrome、safari、opera、other。 $obj->getos(); //获取访客操作系统:windows、mac、linux、unix、bsd、other。 $obj->getip(); //获取访客ip地址。 $obj->getadd(); //获取访客地理位置,使用 baidu 隐藏接口。 $obj->getisp(); //获取访客isp,使用 baidu 隐藏接口。 */ class class_guest_info{ function getlang() { $lang = substr($_server['http_accept_language'], 0, 4); //使用substr()截取字符串,从 0 位开始,截取4个字符 if (preg_match('/zh-c/i',$lang)) { //preg_match()正则表达式匹配函数 $lang = '简体中文'; } elseif (preg_match('/zh/i',$lang)) { $lang = '繁篦中文'; } else { $lang = 'english'; } return $lang; } function getbrowser() { $browser = $_server['http_user_agent']; if (preg_match('/msie/i',$browser)) { $browser = 'msie'; } elseif (preg_match('/firefox/i',$browser)) { $browser = 'firefox'; } elseif (preg_match('/chrome/i',$browser)) { $browser = 'chrome'; } elseif (preg_match('/safari/i',$browser)) { $browser = 'safari'; } elseif (preg_match('/opera/i',$browser)) { $browser = 'opera'; } else { $browser = 'other'; } return $browser; } function getos() { $os = $_server['http_user_agent']; if (preg_match('/win/i',$os)) { $os = 'windows'; } elseif (preg_match('/mac/i',$os)) { $os = 'mac'; } elseif (preg_match('/linux/i',$os)) { $os = 'linux'; } elseif (preg_match('/unix/i',$os)) { $os = 'unix'; } elseif (preg_match('/bsd/i',$os)) { $os = 'bsd'; } else { $os = 'other'; } return $os; } function getip() { if (!empty($_server['http_client_ip'])) { //如果变量是非空或非零的值,则 empty()返回 false。 $ip = explode(',',$_server['http_client_ip']); } elseif (!empty($_server['http_x_forwarded_for'])) { $ip = explode(',',$_server['http_x_forwarded_for']); } elseif (!empty($_server['remote_addr'])) { $ip = explode(',',$_server['remote_addr']); } else { $ip[0] = 'none'; } return $ip[0]; } private function getaddisp() { $ip = $this->getip(); $addisp = mb_convert_encoding(file_get_contents('http://open.baidu.com/ipsearch/s?tn=ipjson&wd='.$ip),'utf-8','gbk'); //mb_convert_encoding() 转换字符编码。 if (preg_match('/noresult/i',$addisp)) { $addisp = 'none'; } else { $sta = stripos($addisp,$ip) + strlen($ip) + strlen('来自'); $len = stripos($addisp,'}')-$sta; $addisp = substr($addisp,$sta,$len); } $addisp = explode(' ',$addisp); return $addisp; } function getadd() { $add = $this->getaddisp(); return $add[0]; } function getisp() { $isp = $this->getaddisp(); if ($isp[0] != 'none' && isset($isp[1])) { $isp = $isp[1]; } else { $isp = 'none'; } return $isp; } } ?>
?
其它类似信息

推荐信息