PHP获取访客IP代码片段

适用场景

注册获取IP,访客获取IP等

代码

function get_ip()
{
	if(!empty($_SERVER['HTTP_CLIENT_IP'])){
		$cip = $_SERVER['HTTP_CLIENT_IP'];
	}else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
		$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	}else if(!empty($_SERVER["REMOTE_ADDR"])){
		$cip = $_SERVER["REMOTE_ADDR"];
	}else{
		$cip = '';
	}
	preg_match("/[\d\.]{7,15}/", $cip, $cips);
	$cip = isset($cips[0]) ? $cips[0] : 'unknown';
	unset($cips);
	return $cip;
}

 

RIPRO主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
秀你码 » PHP获取访客IP代码片段

发表评论

提供最优质的资源集合

立即查看 了解详情