php--获取用户ip
一般在做登录的时候有的会要求同一个帐号不能同时用不同的ip登录,这个时候我们需要获取到用户IP地址
获取ip地址的函数:
function getIP() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
活着不应该靠泪水博取同情,而是需要靠汗水赢得掌声