Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/12/d210716052/htdocs/javatastic/blog/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
My company has recently installed some hardware-based load balancers. Among other things, these load balancers provide a caching proxy for our web applications.
As soon as those went into production, some of our web applications started having problems in obtaining the client IP address. (These were web apps that had reason to check such things.)
This served as a nice reminder that a web application should not trust the client IP address to be accurate. Most ISPs run all web traffic through a proxy, and you never know how many proxies a request will go through before hitting your server.
The proper way to get the client ip address is to use the X-Forwarded-For header.
Now, the X-Forwarded-For header may contain multiple ip addresses. In this case, it will contain a comma-separated list of addresses. The client ip address is the first one in the list.
X-Forwarded-For 172.17.150.97, 126.96.36.199
172.17.15.97 is the actual client ip address
188.8.131.52 is a proxy server
For more information on X-Forwarded-For, see this Wikipedia Article