/**
- 取得IP
- @return string 字符串类型的返回结果
*/
function getIp(){
if (@$_SERVER[‘HTTP_CLIENT_IP’] && $_SERVER[‘HTTP_CLIENT_IP’]!=’unknown’) {
$ip = $_SERVER[‘HTTP_CLIENT_IP’];
} elseif (@$_SERVER[‘HTTP_X_FORWARDED_FOR’] && $_SERVER[‘HTTP_X_FORWARDED_FOR’]!=’unknown’) {
$ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
} else {
$ip = $_SERVER[‘REMOTE_ADDR’];
}
return preg_match(‘/^\d[\d.]+\d$/‘, $ip) ? $ip : ‘’;
}
最后更新: 2018年02月02日 23:43
原始链接: http://tekin.yunnan.ws/PHP技术/201705/30-php-get-ip-address-validate.html