当前位置:博客首页>>PHP >> 阅读正文

php如何取得用户的真实IP

作者: 郑晓 分类: PHP 发布于: 2011-04-16 04:49 浏览:4,321 没有评论


PHP获得用户的真实IP:

<?php
function iptype1 () {
if (getenv("HTTP_CLIENT_IP")) {
return
getenv("HTTP_CLIENT_IP");
}
else {
return "none";
}
}

function iptype2 () {
if (getenv("HTTP_X_FORWARDED_FOR")) {

return getenv("HTTP_X_FORWARDED_FOR");
}
else {
return "none";

}
}
function iptype3 () {
if (getenv("REMOTE_ADDR")) {

return getenv("REMOTE_ADDR");
}
else {
return "none";
}

}
function ip() {
$ip1 = iptype1();
$ip2 = iptype2();
$ip3
= iptype3();
if (isset($ip1) && $ip1 != "none" && $ip1 !=
"unknown") {
return $ip1;
}
elseif (isset($ip2) && $ip2
!= "none" && $ip2 != "unknown") {
return $ip2;
}
elseif
(isset($ip3) && $ip3 != "none" && $ip3 != "unknown") {

return $ip3;
}
else {
return "none";
}
}
/////////
echo ip();
?>
       

本文采用知识共享署名-非商业性使用 3.0 中国大陆许可协议进行许可,转载时请注明出处及相应链接。

本文永久链接: https://www.zh30.com/php-how-to-get-the-users-real-ip.html

发表评论

change vcode