Thursday 26 July 2007

PHP IP Addresses

I keep finding naffexample of how to find someones ip address.

However, I stumbled across this solution;

$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

echo($ip);

It returns the ip address, even if somone is behind a proxy and appears to always return an ip address.

No comments: