当前位置:Gxlcms > PHP教程 > PHP获取用户IP地址

PHP获取用户IP地址

时间:2021-07-01 10:21:17 帮助过:6人阅读

PHP获取用户IP地址

<?php

function getClientIp() {
	$uip = '';
	if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknow')) {
		$uip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		strpos($uip, ',') && list($uip) = explode(',', $uip);
	} elseif(!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknow')) {
		$uip = $_SERVER['HTTP_CLIENT_IP'];
	} elseif(!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknow')) {
		$uip = $_SERVER['REMOTE_ADDR'];
	}
	return $uip;
}
echo getClientIp();

以上就介绍了PHP获取用户IP地址,包括了方面的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行