Published in: PHP
URL: http://snipplr.com/extras/
Are you using $SERVER['REMOTEADDR'] to find the the client's IP address? Well dude, you might be amazed to know that it may not return the true IP address of the client at all time. If your client is connected to the Internet through Proxy Server then $SERVER['REMOTEADDR'] just returns the the IP address of the proxy server not of the client's machine. So here is a simple function in PHP to find the real IP address of the client's machine.
Comments
Subscribe to comments
You need to login to post a comment.

This is not a secure way of getting the real ip address. This is how IP forgery can happen because the first 2 are passed in a users headers.
One line alternative: $ip = !empty($SERVER['HTTPCLIENTIP'])?$SERVER['HTTPCLIENTIP']:(!empty($SERVER['HTTPXFORWARDEDFOR'])?$SERVER['HTTPXFORWARDEDFOR']:$SERVER['REMOTEADDR']);
Agreed, it's very rare that you need to get their forwarded ip.