php函数获取真实客户端IP地址

function getIPaddress(){
$IPaddress='';
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$IPaddress = $_SERVER["HTTP_CLIENT_IP"];
} else {
$IPaddress = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
$IPaddress = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$IPaddress = getenv("HTTP_CLIENT_IP");
} else {
$IPaddress = getenv("REMOTE_ADDR");
}
}
return $IPaddress;
}
使用直接
echo getIPaddress();
上一篇:WPF,Silverlight与XAML读书笔记第四十三 - 多媒体支持之文本与文档


下一篇:linux sed命令详解(转)