detecting visitor’s real IP address

I use this block of codes to detect my visitors real IP address. Sometimes users connect to my site via HTTP proxy. if we rely only on $_SERVER[‘REMOTE_ADDR’], our script would easily spoofed by users.

Here’s the code:

The codes rely on $_SERVER[‘HTTP_X_FORWARDED_FOR’] for proxy connection. Check for local IP block (private network) and fall back to $_SERVER[‘REMOTE_ADDR’] if fail. You may also check $_SERVER[‘HTTP_CLIENT_IP’] variable but in my case, it often return local IP address (private network). After getting this real IP address, you might do some geo IP related services.
Of course this script can’t detect visitor’s real IP address if he/she is using high anonymous proxy server, VPN or SOCKS5 proxy server. Check your browsing anonymity to make sure.

Comments are closed.

%d bloggers like this: