php--獲取用戶ip

通常在作登陸的時候有的會要求同一個賬號不能同時用不一樣的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;
}get

相關文章
相關標籤/搜索