开发者

most reliable way to get ip address of users using php? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Getting Users Real IP address using PHP

I want to log the ip address of anyone who visits my website using a php script to block possible s开发者_运维知识库pammers. Is there a surefire way to find and log anyone's real ip address or a most reliable method?

UPDATE: my website only asks users for a password to log in, no username required. If I want to keep my current method of validation, what other methods can I use to block or deter most spammers?


Function to find real IP address in PHP

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;
}

Source:- http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html


As Dagon said, $_SERVER['REMOTE_ADDR'], at least using Apache.

But then again, it's already in the Apache logs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜