if $_SERVER['HTTP_X_FORWARDED_FOR'] was empty, it would be treated as a false, and would then fall back on $_SERVER['REMOTE_ADDR'], but if $_SERVER['HTTP_X_FORWARDED_FOR'] was not empty, it would be treated as true, and then $ip would equal $_SERVER['HTTP_X_FORWARDED_FOR'];
Okay, then maybe yours would work.. But still prone to Spoofing.. I've seen it myself.. People showing up as 127.0.0.1
This is what the new script protects.. I will explain it clearer...
If somebody visits
http://www.d3xt3r.net this is what the info would show:
$_SERVER['REMOTE_ADDR']: 195.242.99.89 (Server IP)
$_SERVER['HTTP_X_FORWARDED_FOR']: 123.456.789.1 (There IP)
So this script would give the 123.456.789.1 address....
Now, if they were using this address:
http://d3xt3r.net$_SERVER['REMOTE_ADDR']: 123.456.789.1 (Real IP)
$_SERVER['HTTP_X_FORWARDED_FOR']: 127.0.0.1 (SPOOF IP)
Yours would give: 127.0.0.1
Mine would give: 123.456.789.1 REAL IP
See now?
So, really by implementing your script to GET real IP, your making a security loophole.
And also, I believe when the system proxies the address into non-www, it makes "HTTP_X_FORWARDED_FOR" their actual IP from "REMOTE_ADDR".