2014-02-14 98 views
0

如何獲取客戶端的IP地址。如何獲取客戶端的IP地址

我已經通過代理REMOTE_ADDR,HTTP_X_FORWARDED_FOR檢查但都沒有給我正確的IP

REMOTE_ADDR_IP不工作。

+0

你的意思是通過正確的IP,然後呢? – BlitZ

+0

[How to get Client IP address in PHP?](http://stackoverflow.com/questions/3003145/how-to-get-client-ip-address-in-php) –

+0

可能重複的[How我可以在PHP web服務中獲取客戶端的IP地址嗎?](http://stackoverflow.com/questions/1437771/how-can-i-get-the-clients-ip-address-in-a-php-webservice) – Rikesh

回答

1

我用的是最可靠的功能,我發現不久前

function getRealIpAddr() { 
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet 
    { 
     $ip=$_SERVER['HTTP_CLIENT_IP']; 
    } 
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy 
    { 
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; 
    } 
    else 
    { 
     $ip=$_SERVER['REMOTE_ADDR']; 
    } 
    return $ip; 
} 
+0

HTTP_X_FORWARDED_FOR在代理上給我自己的IP,REMOTE_ADDR給代理的IP,有時它交換。這可以如何解決? –

相關問題