Is there a way to collect the IP address of a client connected to your website through a proxy server?
The entire setup is an internal LAN and through the sysadmin, I have control over the proxy machine as well. I am using PHP5 for the website server side.
I tried $_SERVER['REMOTE_ADDR']
in PHP but this variable just stores the IP address of the proxy.
Any ideas?
This code can be used to get the client's IP address who's connecting through a proxy.
But it detects only when proxy is transparent.
Below is the information on HTTP proxy:
Not using any proxy server:
request.getRemoteAddr()
= IP address of clientrequest.getHeader("HTTP_X_FORWARDED_FOR")
= No value or No displayUse Transparent Proxies:
HTTP_X_FORWARDED_FOR
= Real IP address of clientUse Normal Anonymous Proxies:
request.getRemoteAddr()
= IP address of proxy serverHTTP_X_FORWARDED_FOR
= IP address of proxy serverX-Forwarded-For
is the only way to get client's IP address. Check if there is a way to enable that in your proxy.On some proxy, it gives you option how to handle existing XFF header (when request passes through multiple proxies). Here is what you need to consider,
It depends on the proxy. Some proxies add a header which gives the original IP address, the X-Forwarded-For header, but given that most companies uses proxies to hide the internal network structure that's rare. If this is the case then you're not going to be able to do it easily.
If you have control over the proxy then it's time to read the proxy documentation to see how to add that header.
The standard solution (in php) is:
But as the first answer says this all depends on the header actually being set.