如何用php获取客户端正确的ip地址
大家讲道理
大家讲道理 2017-04-10 14:30:06
0
3
357

常用的获取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就不对了,请问该肿么办呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
左手右手慢动作

因为你打错了 http_x_forwared_for

对于HTTP代理、CDN的话,我 以前写的这篇 供参考。

socks5或者vpn代理的话就没办法了。

Peter_Zhu

这个问题已经被讨论烂了,只要客户端想欺骗服务器 你是获取不到真实IP的,不过正常写是没啥问题

洪涛

换个角度想问题吧。你看了那么多电影,有多少家伙不都是因为用代理访问网站所以才能隐藏自己的。如果简单的被你一下就能找到原始ip,那人家不是弱爆了。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template