tags:

views:

271

answers:

1

The getClientIP( ) method that comes with CakePHP is returning private IPs sometimes. For example IPs like 127.0.0.1 or 192.x.x.x. I assume this is caused by proxies.

Looking at the getClientIP( ) code it does seem like it tries to deal with proxies issues but it doesn't really check if the IP is private or not.

What would be the best way to get the real, non-private, IP address?

Thanks.

+2  A: 

Try calling getClientIp(false). If that doesn't work, you could just use $_SERVER["REMOTE_ADDR"] directly instead. It will always contain the external IP that actually connected to the server. This address can't be manipulated, unlike http headers intended for proxies.

Emil H