常用的获取ip方法
function getip() {
if (getenv ( "http_client_ip" ) && strcasecmp ( getenv ( "http_client_ip" ), "unknown" ))
$ip = getenv ( "http_client_ip" );
else if (getenv ( "http_x_forwarded_for" ) && strcasecmp ( getenv ( "http_x_forwared_for" ), "unknown" ))
$ip = getenv ( "http_x_forwarded_for" );
else if (getenv ( "remote_addr" ) && strcasecmp ( getenv ( "remote_addr" ), "unknown" ))
$ip = getenv ( "remote_addr" );
else if (isset ( $_SERVER ["REMOTE_ADDR"] ) && $_SERVER ["REMOTE_ADDR"] && strcasecmp ( $_SERVER ["REMOTE_ADDR"], "unknown" ))
$ip = $_SERVER ["REMOTE_ADDR"];
else
$ip = "unknown";
return ($ip);
}
但用代理后取得的ip就不对了,请问该肿么办呢?
因为你打错了
http_x_forwared_for
对于HTTP代理、CDN的话,我 以前写的这篇 供参考。
socks5或者vpn代理的话就没办法了。