一般在做登录的时候有的会要求同一个帐号不能同时用不同的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;
}
时间: 2024-10-08 02:23:18