0

0

PHP获取客户端操作系统,浏览器,语言,IP,IP归属地等

PHP中文网

PHP中文网

发布时间:2016-05-25 17:08:47

|

2155人浏览过

|

来源于php中文网

原创

1. [代码][PHP]代码    

1) $matches[1] = 'Lion '.$matches[1];
			elseif(count(explode(8,$matches[1]))>1) $matches[1] = 'Mountain Lion '.$matches[1];
			$os_ver = "X ".$matches[1];
		} elseif (preg_match('/Macintosh/i', $ua)) {
			$os_name = "Mac OS";
			$os_code = "macos";
		} elseif (preg_match('/Unix/i', $ua)) {
			$os_name = "UNIX";
			$os_code = "unix";
		} elseif (preg_match('/CrOS/i', $ua)){
			$os_name="Google Chrome OS";
			$os_code="chromeos";
		} elseif (preg_match('/Fedor.([0-9. _]+)/i', $ua, $matches)){
			$os_name="Fedora";
			$os_code="fedora";
			$os_ver = $matches[1];
		} else{
			$os_name = 'Unknow Os';
			$os_code = 'other';
		}
		 
		return array($os_name, $os_code, $os_ver);
	}
	
	function CID_pda_detect_os($ua) {
		$os_name = $os_code = $os_ver = $pda_name = $pda_code = $pda_ver = null;
		if (preg_match('#PalmOS#i', $ua)) {
			$os_name = "Palm OS";
			$os_code = "palm";
		} elseif (preg_match('#Windows CE#i', $ua)) {
			$os_name = "Windows CE";
			$os_code = "windows";
		} elseif (preg_match('#QtEmbedded#i', $ua)) {
			$os_name = "Qtopia";
			$os_code = "linux";
		} elseif (preg_match('#Zaurus#i', $ua)) {
			$os_name = "Linux";
			$os_code = "linux";
		} elseif (preg_match('#Symbian#i', $ua)) {
			$os_name = "Symbian OS";
			$os_code = "symbian";
		} elseif (preg_match('#PalmOS/sony/model#i', $ua)) {
			$pda_name = "Sony Clie";
			$pda_code = "sony";
		} elseif (preg_match('#Zaurus ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$pda_name = "Sharp Zaurus " . $matches[1];
			$pda_code = "zaurus";
			$pda_ver = $matches[1];
		} elseif (preg_match('#Series ([0-9]+)#i', $ua, $matches)) {
			$pda_name = "Series";
			$pda_code = "nokia";
			$pda_ver = $matches[1];
		} elseif (preg_match('#Nokia ([0-9]+)#i', $ua, $matches)) {
			$pda_name = "Nokia";
			$pda_code = "nokia";
			$pda_ver = $matches[1];
		} elseif (preg_match('#SIE-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Siemens";
			$pda_code = "siemens";
			$pda_ver = $matches[1];
		} elseif (preg_match('#dopod([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Dopod";
			$pda_code = "dopod";
			$pda_ver = $matches[1];
		} elseif (preg_match('#o2 xda ([a-zA-Z0-9 ]+);#i', $ua, $matches)) {
			$pda_name = "O2 XDA";
			$pda_code = "o2";
			$pda_ver = $matches[1];
		} elseif (preg_match('#SEC-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Samsung";
			$pda_code = "samsung";
			$pda_ver = $matches[1];
		} elseif (preg_match('#SonyEricsson ?([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "SonyEricsson";
			$pda_code = "sonyericsson";
			$pda_ver = $matches[1];
		} elseif (preg_match('#Kindle\/([a-zA-Z0-9. ×\(.\)]+)#i',$ua, $matches)) {//for Kindle
			$pda_name = "kindle";
			$pda_code = "kindle";
			$pda_ver = $matches[1];
		} else {
			$pda_name = 'Unknow Os';
			$pda_code = 'other';
		}
		 
		return array($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver);
	}
	
	function CID_detect_browser($ua) {
		$browser_name = $browser_code = $browser_ver = $os_name = $os_code = $os_ver = $pda_name = $pda_code = $pda_ver = null;
		$ua = preg_replace("/FunWebProducts/i", "", $ua);
		if (preg_match('#MovableType[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'MovableType';
			$browser_code = 'mt';
			$browser_ver = $matches[1];
		} elseif (preg_match('#WordPress[ /]([a-zA-Z0-9.]*)#i', $ua, $matches)) {
			$browser_name = 'WordPress';
			$browser_code = 'wp';
			$browser_ver = $matches[1];
		} elseif (preg_match('#typepad[ /]([a-zA-Z0-9.]*)#i', $ua, $matches)) {
			$browser_name = 'TypePad';
			$browser_code = 'typepad';
			$browser_ver = $matches[1];
		} elseif (preg_match('#drupal#i', $ua)) {
			$browser_name = 'Drupal';
			$browser_code = 'drupal';
			$browser_ver = count($matches) > 0 ? $matches[1] : "";
		} elseif (preg_match('#symbianos/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$os_name = "SymbianOS";
			$os_ver = $matches[1];
			$os_code = 'symbian';
		} elseif (preg_match('#avantbrowser.com#i', $ua)) {
			$browser_name = 'Avant Browser';
			$browser_code = 'avantbrowser';
		} elseif (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Camino';
			$browser_code = 'camino';
			$browser_ver = $matches[2];
			$os_name = "Mac OS";
			$os_code = "macos";
			$os_ver = "X";
		} elseif (preg_match('#anonymouse#i', $ua, $matches)) {
			$browser_name = 'Anonymouse';
			$browser_code = 'anonymouse';
		} elseif (preg_match('#PHP#', $ua, $matches)) {
			$browser_name = 'PHP';
			$browser_code = 'php';
		} elseif (preg_match('#danger hiptop#i', $ua, $matches)) {
			$browser_name = 'Danger HipTop';
			$browser_code = 'danger';
		} elseif (preg_match('#w3m/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'W3M';
			$browser_code = 'w3m';
			$browser_ver = $matches[1];
		} elseif (preg_match('#Shiira[/]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Shiira';
			$browser_code = 'shiira';
			$browser_ver = $matches[1];
			$os_name = "Mac OS";
			$os_code = "macos";
			$os_ver = "X";
		} elseif (preg_match('#Dillo[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Dillo';
			$browser_code = 'dillo';
			$browser_ver = $matches[1];
		} elseif (preg_match('#Epiphany/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Epiphany';
			$browser_code = 'epiphany';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#UP.Browser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Openwave UP.Browser';
			$browser_code = 'openwave';
			$browser_ver = $matches[1];
		} elseif (preg_match('#DoCoMo/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'DoCoMo';
			$browser_code = 'docomo';
			$browser_ver = $matches[1];
			if ($browser_ver == '1.0') {
				preg_match('#DoCoMo/([a-zA-Z0-9.]+)/([a-zA-Z0-9.]+)#i', $ua, $matches);
				$browser_ver = $matches[2];
			} elseif ($browser_ver == '2.0') {
				preg_match('#DoCoMo/([a-zA-Z0-9.]+) ([a-zA-Z0-9.]+)#i', $ua, $matches);
				$browser_ver = $matches[2];
			}
		} elseif (preg_match('#(SeaMonkey)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Mozilla SeaMonkey';
			$browser_code = 'seamonkey';
			$browser_ver = $matches[2];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Kazehakase/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Kazehakase';
			$browser_code = 'kazehakase';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Flock/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Flock';
			$browser_code = 'flock';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/4([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Mozilla Firefox';
			$browser_code = 'firefox';
			$browser_ver = '4'.$matches[2];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Mozilla Firefox';
			$browser_code = 'firefox';
			$browser_ver = $matches[2];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Minimo/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Minimo';
			$browser_code = 'mozilla';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#MultiZilla/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'MultiZilla';
			$browser_code = 'mozilla';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'SouGou Browser';
			$browser_code = 'sogou';
			$browser_ver = '2'.$matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#baidubrowser ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'BaiDu Browser';
			$browser_code = 'baidubrowser';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = '360 Browser';
			$browser_code = '360se';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#QQBrowser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'QQ Browser';
			$browser_code = 'qqbrowser';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('/PSP \(PlayStation Portable\)\; ([a-zA-Z0-9.]+)/', $ua, $matches)) {
			$pda_name = "Sony PSP";
			$pda_code = "sony-psp";
			$pda_ver = $matches[1];
		} elseif (preg_match('#Galeon/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Galeon';
			$browser_code = 'galeon';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#iCab/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'iCab';
			$browser_code = 'icab';
			$browser_ver = $matches[1];
			$os_name = "Mac OS";
			$os_code = "macos";
			if (preg_match('#Mac OS X#i', $ua)) {
				$os_ver = "X";
			}
		} elseif (preg_match('#K-Meleon/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'K-Meleon';
			$browser_code = 'kmeleon';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Lynx/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Lynx';
			$browser_code = 'lynx';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#Links \\(([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Links';
			$browser_code = 'lynx';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#ELinks[/ ]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'ELinks';
			$browser_code = 'lynx';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#ELinks \\(([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'ELinks';
			$browser_code = 'lynx';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
		} elseif (preg_match('#Konqueror/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Konqueror';
			$browser_code = 'konqueror';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			if (!$os_name) {
				list($os_name, $os_code, $os_ver) = self::CID_pda_detect_os($ua);
			}
		} elseif (preg_match('#NetPositive/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'NetPositive';
			$browser_code = 'netpositive';
			$browser_ver = $matches[1];
			$os_name = "BeOS";
			$os_code = "beos";
		} elseif (preg_match('#OmniWeb#i', $ua)) {
			$browser_name = 'OmniWeb';
			$browser_code = 'omniweb';
			$os_name = "Mac OS";
			$os_code = "macos";
			$os_ver = "X";
		} elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Google Chrome'; $browser_code = 'chrome'; $browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Arora/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Arora';
			$browser_code = 'arora';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua,$matches)) {
			$browser_name = 'Maxthon';
			$browser_code = 'maxthon';
			$browser_ver = $matches[2];
			if (preg_match('/Win/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#CriOS/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Chrome for iOS';
			$browser_code = 'crios';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Safari';
			$browser_code = 'safari';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#opera mini#i', $ua)) {
			$browser_name = 'Opera Mini';
			$browser_code = 'opera';
			preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches);
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#Opera.(.*)Version[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Opera';
			$browser_code = 'opera';
			$browser_ver = $matches[2];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
			if (!$os_name) {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
			if (!$os_name) {
				list($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = self::CID_pda_detect_os($ua);
			}
			if (!$os_name) {
				if (preg_match('/Wii/i', $ua)) {
					$os_name = "Nintendo Wii";
					$os_code = "nintendo-wii";
				}
			}
		} elseif (preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Opera Mini';
			$browser_code = 'opera';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#WebPro/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'WebPro';
			$browser_code = 'webpro';
			$browser_ver = $matches[1];
			$os_name = "PalmOS";
			$os_code = "palmos";
		} elseif (preg_match('#WebPro#i', $ua, $matches)) {
			$browser_name = 'WebPro';
			$browser_code = 'webpro';
			$os_name = "PalmOS";
			$os_code = "palmos";
		} elseif (preg_match('#Netfront/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Netfront';
			$browser_code = 'netfront';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = self::CID_pda_detect_os($ua);
		} elseif (preg_match('#Xiino/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Xiino';
			$browser_code = 'xiino';
			$browser_ver = $matches[1];
		} elseif (preg_match('/wp-blackberry\/([a-zA-Z0-9.]*)/i', $ua, $matches)) {
			$browser_name = "WordPress for BlackBerry";
			$browser_code = "wordpress";
			$browser_ver = $matches[1];
			$pda_name = "BlackBerry";
			$pda_code = "blackberry";
		} elseif (preg_match('#Blackberry([0-9]+)#i', $ua, $matches)) {
			$pda_name = "Blackberry";
			$pda_code = "blackberry";
			$pda_ver = $matches[1];
		} elseif (preg_match('#Blackberry#i', $ua)) {
			$pda_name = "Blackberry";
			$pda_code = "blackberry";
		} elseif (preg_match('#SPV ([0-9a-zA-Z.]+)#i', $ua, $matches)) {
			$pda_name = "Orange SPV";
			$pda_code = "orange";
			$pda_ver = $matches[1];
		} elseif (preg_match('#LGE-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "LG";
			$pda_code = 'lg';
			$pda_ver = $matches[1];
		} elseif (preg_match('#MOT-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Motorola";
			$pda_code = 'motorola';
			$pda_ver = $matches[1];
		} elseif (preg_match('#Nokia ?([0-9]+)#i', $ua, $matches)) {
			$pda_name = "Nokia";
			$pda_code = "nokia";
			$pda_ver = $matches[1];
		} elseif (preg_match('#NokiaN-Gage#i', $ua)) {
			$pda_name = "Nokia";
			$pda_code = "nokia";
			$pda_ver = "N-Gage";
		} elseif (preg_match('#Blazer[ /]?([a-zA-Z0-9.]*)#i', $ua, $matches)) {
			$browser_name = "Blazer";
			$browser_code = "blazer";
			$browser_ver = $matches[1];
			$os_name = "Palm OS";
			$os_code = "palm";
		} elseif (preg_match('#SIE-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Siemens";
			$pda_code = "siemens";
			$pda_ver = $matches[1];
		} elseif (preg_match('#SEC-([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "Samsung";
			$pda_code = "samsung";
			$pda_ver = $matches[1];
		} elseif (preg_match('/wp-iphone\/([a-zA-Z0-9.]*)/i', $ua, $matches)) {
			$browser_name = "WordPress for iOS";
			$browser_code = "wordpress";
			$browser_ver = $matches[1];
			$pda_name = "iPhone & iPad";
			$pda_code = "ipad";
		} elseif (preg_match('/wp-android\/([a-zA-Z0-9.]*)/i', $ua, $matches)) {
			$browser_name = "WordPress for Android";
			$browser_code = "wordpress";
			$browser_ver = $matches[1];
			$pda_name = "Android";
			$pda_code = "android";
		} elseif (preg_match('/wp-windowsphone\/([a-zA-Z0-9.]*)/i', $ua, $matches)) {
			$browser_name = "WordPress for Windows Phone 7";
			$browser_code = "wordpress";
			$browser_ver = $matches[1];
			$pda_name = "Windows Phone 7";
			$pda_code = "windows_phone7";
		} elseif (preg_match('/wp-nokia\/([a-zA-Z0-9.]*)/i', $ua, $matches)) {
			$browser_name = "WordPress for Nokia";
			$browser_code = "wordpress";
			$browser_ver = $matches[1];
			$pda_name = "Nokia";
			$pda_code = "nokia";
		} elseif (preg_match('#SAMSUNG-(S.H-[a-zA-Z0-9_/.]+)#i', $ua, $matches)) {
			$pda_name = "Samsung";
			$pda_code = "samsung";
			$pda_ver = $matches[1];
			if (preg_match('#(j2me|midp)#i', $ua)) {
				$browser_name = "J2ME/MIDP Browser";
				$browser_code = "j2me";
			}
		} elseif (preg_match('#SonyEricsson ?([a-zA-Z0-9]+)#i', $ua, $matches)) {
			$pda_name = "SonyEricsson";
			$pda_code = "sonyericsson";
			$pda_ver = $matches[1];
		} elseif (preg_match('#(j2me|midp)#i', $ua)) {
			$browser_name = "J2ME/MIDP Browser";
			$browser_code = "j2me";
			// mice
		} elseif (preg_match('/GreenBrowser/i', $ua)) {
			$browser_name = 'GreenBrowser';
			$browser_code = 'greenbrowser';
			if (preg_match('/Win/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = '腾讯TT浏览器';
			$browser_code = 'tencenttraveler';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'UCWEB';
			$browser_code = 'ucweb';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Internet Explorer';
			$browser_ver = $matches[1];
			if ( strpos($browser_ver, '7') !== false || strpos($browser_ver, '8') !== false)
				$browser_code = 'ie8';
			elseif ( strpos($browser_ver, '9') !== false)
			$browser_code = 'ie9';
			elseif ( strpos($browser_ver, '10') !== false)
			$browser_code = 'ie10';
			else
				$browser_code = 'ie';
			list($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = self::CID_windows_detect_os($ua);
		} elseif (preg_match('#Universe/([0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Universe';
			$browser_code = 'universe';
			$browser_ver = $matches[1];
			list($os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver) = self::CID_pda_detect_os($ua);
		}elseif (preg_match('#Netscape[0-9]?/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Netscape';
			$browser_code = 'netscape';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#^Mozilla/5.0#i', $ua) && preg_match('#rv:([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Mozilla';
			$browser_code = 'mozilla';
			$browser_ver = $matches[1];
			if (preg_match('/Windows/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		} elseif (preg_match('#^Mozilla/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
			$browser_name = 'Netscape Navigator';
			$browser_code = 'netscape';
			$browser_ver = $matches[1];
			if (preg_match('/Win/i', $ua)) {
				list($os_name, $os_code, $os_ver) = self::CID_windows_detect_os($ua);
			} else {
				list($os_name, $os_code, $os_ver) = self::CID_unix_detect_os($ua);
			}
		}else{
			$browser_name = 'Unknow Browser';
			$browser_code = 'null';
		}
	
		if (!$pda_name && !$os_name){
			$pda_name = 'Unknow Os';
			$pda_code = 'other';
			$os_name = 'Unknow Os';
			$os_code = 'other';
		}
		return array($browser_name, $browser_code, $browser_ver, $os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver);
	}
  ////获得访客浏览器类型
	function Get_Useragent(){
		if(!empty($_SERVER['HTTP_USER_AGENT'])){
			return self::CID_detect_browser($_SERVER['HTTP_USER_AGENT']);
   		}
   		else{
   			return array();
   		} 
  }
  
  ////获得访客真实ip
	function Get_Ip_Addr(){
   		if(!empty($_SERVER["HTTP_CLIENT_IP"])){   
      		$ip = $_SERVER["HTTP_CLIENT_IP"];
   		}
   		if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ //获取代理ip
    		$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
	      		$ip = $ips[$i];
	      		break;    
	      	}  
		}  
   		$tip = empty($_SERVER['REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR']; 
   		if($tip=="127.0.0.1"){ //获得本地真实IP
      		return self::get_onlineip();   
   		}
   		else{
      		return $tip; 
   		}
  }
  
  ////获得本地真实IP
  function get_onlineip() {
		$ip_json = @file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=myip");
		$ip_arr=json_decode(stripslashes($ip_json),1);
		if($ip_arr['code']==0)
		{
			return $ip_arr['data']['ip'];
		}
		
   }
  
  ////根据ip获得访客所在地地名
	function Get_Ip_From($ip=''){
		if(empty($ip)){
			$ip = self::Getip();    
		}
   		$ip_json=@file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);//根据taobao ip
   		$ip_arr=json_decode(stripslashes($ip_json),1);
   		if($ip_arr['code']==0)
   		{
   			return $ip_arr['data'];
   		}
   		else
   		{
   			return false;
   		}
   		
	} 

}

                   

中解商务通
中解商务通

实时捕捉 一旦访问者打开您的网站,系统会立即显示,这时您就可以查看用户的信息,如:来自搜索引擎关键词、友情链接或直接访问;访问者的IP地址,所在地区,正在访问哪个网页;以及访问者使用的操作系统、浏览器、显示器屏幕分辨率颜色深度等。 主动出击 变被动为主动,可以主动邀请访问者进行洽谈勾通,帮助客户深入了解您的企业和产品,同时获得对方的采购意向、联系方式等信息。 互动交流 主动销售和在线客服合二为一,

下载

                   

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

php

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
Java 项目构建与依赖管理(Maven / Gradle)
Java 项目构建与依赖管理(Maven / Gradle)

本专题系统讲解 Java 项目构建与依赖管理的完整体系,重点覆盖 Maven 与 Gradle 的核心概念、项目生命周期、依赖冲突解决、多模块项目管理、构建加速与版本发布规范。通过真实项目结构示例,帮助学习者掌握 从零搭建、维护到发布 Java 工程的标准化流程,提升在实际团队开发中的工程能力与协作效率。

3

2026.01.12

c++主流开发框架汇总
c++主流开发框架汇总

本专题整合了c++开发框架推荐,阅读专题下面的文章了解更多详细内容。

98

2026.01.09

c++框架学习教程汇总
c++框架学习教程汇总

本专题整合了c++框架学习教程汇总,阅读专题下面的文章了解更多详细内容。

53

2026.01.09

学python好用的网站推荐
学python好用的网站推荐

本专题整合了python学习教程汇总,阅读专题下面的文章了解更多详细内容。

139

2026.01.09

学python网站汇总
学python网站汇总

本专题整合了学python网站汇总,阅读专题下面的文章了解更多详细内容。

12

2026.01.09

python学习网站
python学习网站

本专题整合了python学习相关推荐汇总,阅读专题下面的文章了解更多详细内容。

19

2026.01.09

俄罗斯手机浏览器地址汇总
俄罗斯手机浏览器地址汇总

汇总俄罗斯Yandex手机浏览器官方网址入口,涵盖国际版与俄语版,适配移动端访问,一键直达搜索、地图、新闻等核心服务。

84

2026.01.09

漫蛙稳定版地址大全
漫蛙稳定版地址大全

漫蛙稳定版地址大全汇总最新可用入口,包含漫蛙manwa漫画防走失官网链接,确保用户随时畅读海量正版漫画资源,建议收藏备用,避免因域名变动无法访问。

437

2026.01.09

php学习网站大全
php学习网站大全

精选多个优质PHP入门学习网站,涵盖教程、实战与文档,适合零基础到进阶开发者,助你高效掌握PHP编程。

49

2026.01.09

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

相关下载

更多

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PHP课程
PHP课程

共137课时 | 8.5万人学习

JavaScript ES5基础线上课程教学
JavaScript ES5基础线上课程教学

共6课时 | 6.9万人学习

PHP新手语法线上课程教学
PHP新手语法线上课程教学

共13课时 | 0.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号