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 spammers. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With