PHP获取用户操作系统、浏览器、ip信息_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > PHP获取用户操作系统、浏览器、ip信息

PHP获取用户操作系统、浏览器、ip信息

 2011/1/9 9:16:41  flyer0126  http://flyer0126.javaeye.com  我要评论(0)
  • 摘要:<?php//--------------------------------------------------//分析返回用户操作系统名称//--------------------------------------------------functiongetSystem(){$sys=$_SERVER['HTTP_USER_AGENT'];if(stripos($sys,"NT6.1"))$os="Windows7";elseif(stripos($sys,"NT6.0")
  • 标签:PHP 浏览 用户 浏览器 操作
<?php

// --------------------------------------------------
// 分析返回用户操作系统名称
// --------------------------------------------------
function getSystem(){
	$sys = $_SERVER['HTTP_USER_AGENT'];
	if(stripos($sys, "NT 6.1"))
	   $os = "Windows 7";
	elseif(stripos($sys, "NT 6.0"))
	   $os = "Windows Vista";
	elseif(stripos($sys, "NT 5.1"))
	   $os = "Windows XP";
	elseif(stripos($sys, "NT 5.2"))
	   $os = "Windows Server 2003";
	elseif(stripos($sys, "NT 5"))
	   $os = "Windows 2000";
	elseif(stripos($sys, "NT 4.9"))
	   $os = "Windows ME";
	elseif(stripos($sys, "NT 4"))
	   $os = "Windows NT 4.0";
	elseif(stripos($sys, "98"))
	   $os = "Windows 98";
	elseif(stripos($sys, "95"))
	   $os = "Windows 95";
	elseif(stripos($sys, "Mac"))
	   $os = "Mac";
	elseif(stripos($sys, "Linux"))
	   $os = "Linux";
	elseif(stripos($sys, "Unix"))
	   $os = "Unix";
	elseif(stripos($sys, "FreeBSD"))
	   $os = "FreeBSD";
	elseif(stripos($sys, "SunOS"))
	   $os = "SunOS";
	elseif(stripos($sys, "BeOS"))
	   $os = "BeOS";
	elseif(stripos($sys, "OS/2"))
	   $os = "OS/2";
	elseif(stripos($sys, "PC"))
	   $os = "Macintosh";
	elseif(stripos($sys, "AIX"))
	   $os = "AIX";
	else
	   $os = "未知操作系统";
  
	return $os;
}

// --------------------------------------------------
// 分析返回用户网页浏览器名称
// --------------------------------------------------
function getBrowser(){
	$browser = $_SERVER['HTTP_USER_AGENT'];
	if(strpos(strtolower($browser),"netcaptor"))
	   $exp = "NetCaptor";
	elseif(strpos(strtolower($browser),"firefox")){
	   preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
	   $exp = "Mozilla Firefox ".$b[1];
	}elseif(strpos(strtolower($browser),"maxthon")){
	   preg_match("/MAXTHON\s+([^;)]+)+/i", $sys, $b);
	   preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
	   $exp = $b[0]." (IE".$ie[1].")";
	}elseif(strpos(strtolower($browser),"msie")){
	   preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
	   $exp = "Internet Explorer ".$ie[1];
	}elseif(strpos(strtolower($browser),"netscape"))
	   $exp = "Netscape";
	elseif(strpos(strtolower($browser),"opera"))
	   $exp = "Opera";
	else
	   $exp = "未知浏览器";
	  
	return $exp;
}

// --------------------------------------------------
// 分析返回用户ip
// --------------------------------------------------
function getIp(){
	$ip = '';
	if ($_SERVER["HTTP_X_FORWARDED_FOR"]){
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	}elseif ($_SERVER["HTTP_CLIENT_IP"]){
		$ip = $_SERVER["HTTP_CLIENT_IP"];
	}elseif ($_SERVER["REMOTE_ADDR"]){
		$ip = $_SERVER["REMOTE_ADDR"];
	}elseif (getenv("HTTP_X_FORWARDED_FOR")){
		$ip = getenv("HTTP_X_FORWARDED_FOR");
	}elseif (getenv("HTTP_CLIENT_IP")){
		$ip = getenv("HTTP_CLIENT_IP");
	}elseif (getenv("REMOTE_ADDR")){
		$ip = getenv("REMOTE_ADDR");
	}else{
		$ip = "unknown";
	}
	
	return $ip;
}

?>
?
发表评论
用户名: 匿名