<?php
function get_broswer(){
$sys = $_SERVER['HTTP_USER_AGENT'];
$exp[0] = "未知浏览器";
$exp[1] = "";
if (stripos($sys, "Firefox/") > 0) {
preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
$exp[0] = "Firefox";
$exp[1] = $b[1];
} if (stripos($sys, "Maxthon") > 0) {
preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou);
$exp[0] = "傲游";
$exp[1] = $aoyou[1];
} if (stripos($sys, "MSIE") > 0) {
preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
$exp[0] = "IE";
$exp[1] = $ie[1];
} if (stripos($sys, "OPR") > 0) {
preg_match("/OPR\/([\d\.]+)/", $sys, $opera);
$exp[0] = "Opera";
$exp[1] = $opera[1];
} if(stripos($sys, "Edge") > 0) {
preg_match("/Edge\/([\d\.]+)/", $sys, $Edge);
$exp[0] = "Edge";
$exp[1] = $Edge[1];
} if (stripos($sys, "Chrome") > 0) {
preg_match("/Chrome\/([\d\.]+)/", $sys, $google);
$exp[0] = "Chrome";
$exp[1] = $google[1];
} if(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){
preg_match("/rv:([\d\.]+)/", $sys, $IE);
$exp[0] = "IE";
$exp[1] = $IE[1];
}
return $exp[0].'('.$exp[1].')';
}
function get_os(){
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = '未知操作系统';
if (preg_match('/win/i', $agent) && strpos($agent, '95'))
{
$os = 'Windows 95';
}
if (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90'))
{
$os = 'Windows ME';
}
if (preg_match('/win/i', $agent) && preg_match('/98/i', $agent))
{
$os = 'Windows 98';
}
if (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent))
{
$os = 'Windows NT';
}
if (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent))
{
$os = 'Windows Vista';
}
if (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent))
{
$os = 'Windows 7';
}
if (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent))
{
$os = 'Windows 8';
}
if(preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent))
{
$os = 'Windows 10';
}
if (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent))
{
$os = 'Windows XP';
}
if (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent))
{
$os = 'Windows 2000';
}
if (preg_match('/win/i', $agent) && preg_match('/32/i', $agent))
{
$os = 'Windows 32';
}
if (preg_match('/linux/i', $agent))
{
$os = 'Linux';
}
if (preg_match('/unix/i', $agent))
{
$os = 'Unix';
}
if (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent))
{
$os = 'SunOS';
}
if (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent))
{
$os = 'IBM OS/2';
}
if (preg_match('/Mac/i', $agent) && preg_match('/PC/i', $agent))
{
$os = 'Macintosh';
}
if (preg_match('/PowerPC/i', $agent))
{
$os = 'PowerPC';
}
if (preg_match('/AIX/i', $agent))
{
$os = 'AIX';
}
if (preg_match('/HPUX/i', $agent))
{
$os = 'HPUX';
}
if (preg_match('/NetBSD/i', $agent))
{
$os = 'NetBSD';
}
if (preg_match('/BSD/i', $agent))
{
$os = 'BSD';
}
if (preg_match('/OSF1/i', $agent))
{
$os = 'OSF1';
}
if (preg_match('/IRIX/i', $agent))
{
$os = 'IRIX';
}
if (preg_match('/FreeBSD/i', $agent))
{
$os = 'FreeBSD';
}
if (preg_match('/teleport/i', $agent))
{
$os = 'teleport';
}
if (preg_match('/flashget/i', $agent))
{
$os = 'flashget';
}
if (preg_match('/webzip/i', $agent))
{
$os = 'webzip';
}
if (preg_match('/offline/i', $agent))
{
$os = 'offline';
}
if(strpos($agent, 'iphone')){
$os = 'iphone';
}
if(strpos($agent, 'ipad')){
$os = 'ipad';
}
if(strpos($agent, 'android')){
$os = 'android';
}
if (stripos($agent, "SAMSUNG")!==false || stripos($agent, "Galaxy")!==false || strpos($agent, "GT-")!==false || strpos($agent, "SCH-")!==false || strpos($agent, "SM-")!==false) {
$os = 'android ->三星';
}
if (stripos($agent, "Huawei")!==false || stripos($agent, "Honor")!==false || stripos($agent, "H60-")!==false || stripos($agent, "H30-")!==false) {
$os = 'android ->华为';
}
if (stripos($agent, "Lenovo")!==false) {
$os = 'android ->联想';
}
if (strpos($agent, "MI-ONE")!==false || strpos($agent, "MI 1S")!==false || strpos($agent, "MI 2")!==false || strpos($agent, "MI 3")!==false || strpos($agent, "MI 4")!==false || strpos($agent, "MI-4")!==false) {
$os = 'android ->小米';
}
if (strpos($agent, "HM NOTE")!==false || strpos($agent, "HM201")!==false) {
$os = 'android ->红米';
}
if (stripos($agent, "Coolpad")!==false || strpos($agent, "8190Q")!==false || strpos($agent, "5910")!==false) {
$os = 'android ->酷派';
}
if (stripos($agent, "ZTE")!==false || stripos($agent, "X9180")!==false || stripos($agent, "N9180")!==false || stripos($agent, "U9180")!==false) {
$os = 'android ->中兴';
}
if (stripos($agent, "OPPO")!==false || strpos($agent, "X9007")!==false || strpos($agent, "X907")!==false || strpos($agent, "X909")!==false || strpos($agent, "R831S")!==false || strpos($agent, "R827T")!==false || strpos($agent, "R821T")!==false || strpos($agent, "R811")!==false || strpos($agent, "R2017")!==false) {
$os = 'android ->OPPO';
}
if (strpos($agent, "HTC")!==false || stripos($agent, "Desire")!==false) {
$os = 'android ->HTC';
}
if (stripos($agent, "vivo")!==false) {
$os = 'android ->vivo';
}
if (stripos($agent, "K-Touch")!==false) {
$os = 'android ->天语';
}
if (stripos($agent, "Nubia")!==false || stripos($agent, "NX50")!==false || stripos($agent, "NX40")!==false) {
$os = 'android ->努比亚';
}
if (strpos($agent, "M045")!==false || strpos($agent, "M032")!==false || strpos($agent, "M355")!==false) {
$os = 'android ->魅族';
}
if (stripos($agent, "DOOV")!==false) {
$os = 'android ->朵唯';
}
if (stripos($agent, "GFIVE")!==false) {
$os = 'android ->基伍';
}
if (stripos($agent, "Gionee")!==false || strpos($agent, "GN")!==false) {
$os = 'android ->金立';
}
if (stripos($agent, "HS-U")!==false || stripos($agent, "HS-E")!==false) {
$os = 'android ->海信';
}
if (stripos($agent, "Nokia")!==false) {
$os = 'android ->诺基亚';
}
return $os;
}
function isMobile(){
$code = 2;
if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
{
$code = 1;
}
if (isset ($_SERVER['HTTP_VIA']))
{
$code = stristr($_SERVER['HTTP_VIA'], "wap") ? 1 : 2;
}
if (isset ($_SERVER['HTTP_USER_AGENT']))
{
$clientkeywords = array ('nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sharp',
'sie-',
'philips',
'panasonic',
'alcatel',
'lenovo',
'iphone',
'ipod',
'blackberry',
'meizu',
'android',
'netfront',
'symbian',
'ucweb',
'windowsce',
'palm',
'operamini',
'operamobi',
'openwave',
'nexusone',
'cldc',
'midp',
'wap',
'mobile'
);
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
{
$code = 1;
}
}
if (isset ($_SERVER['HTTP_ACCEPT']))
{
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
{
$code = 1;
}
}
return $code;
}
function get_client_ip()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
if(empty($ip))$ip = "unknown";
return ($ip);
}
function Getip()
{
if (! empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
}
if ($ip) {
$ips = array_unshift($ips, $ip);
}
$count = count($ips);
for ($i = 0; $i < $count; $i ++) {
if (! preg_match("/^(10|172\.16|192\.168)\./i", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
$tip = empty($_SERVER['REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR'];
if ($tip == "127.0.0.1") {
return getLocalIP();
} else {
return $tip;
}
}
function getLocalIP() {
$preg = "/\A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\Z/";
exec("ipconfig", $out, $stats);
if (!empty($out)) {
foreach ($out AS $row) {
if (strstr($row, "IP") && strstr($row, ":") && !strstr($row, "IPv6")) {
$tmpIp = explode(":", $row);
if (preg_match($preg, trim($tmpIp[1]))) {
return trim($tmpIp[1]);
}
}
}
}
exec("ifconfig", $out, $stats);
if (!empty($out)) {
if (isset($out[1]) && strstr($out[1], 'addr:')) {
$tmpArray = explode(":", $out[1]);
$tmpIp = explode(" ", $tmpArray[1]);
if (preg_match($preg, trim($tmpIp[0]))) {
return trim($tmpIp[0]);
}
}
}
return '127.0.0.1';
}
function Getaddress($ip = '')
{
if (empty($ip)) {
$ip = $this->Getip();
}
$ipadd = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=" . $ip);
if ($ipadd) {
$charset = iconv("gbk", "utf-8", $ipadd);
preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $charset, $ipadds);
return $ipadds;
} else {
return "addree is none";
}
}
|