HTTP_X_FORWARDED_FOR, HTTP_VIA and REMOTE_ADDR Explained
These PHP server variables provide the IP address information in different ways based on the condition how the website is accessed. So basically these variables used to track the user’s location.
You can get these information with the help of below three server variables.
- REMOTE_ADDR
- HTTP_VIA
- HTTP_X_FORWARDED_FOR
When any user visit your site without any proxy server in that case you can get the IP address using REMOTE_ADDR server variable. So in that case HTTP_X_FORWARDED_FOR and HTTP_VIA will not be available.
Note: HTTP_VIA and HTTP_X_FORWARDED_FOR will be only populated if web server detects the use of the Proxy Server.
Now for understanding the HTTP_VIA and HTTP_X_FORWARDED_FOR check the below scenario:
Suppose any user from India visits my site from the proxy server of the USA. Below I have listed the user’s flow with dummy IP addresses.
User( India 1.25.32.51 ) >> Proxy (USA 54.58.210.255) >> https://xpertdeveloper.com
AS per above scenario REMOTE_ADDRESS will populated with 54.58.210.255, HTTP_VIA will populated with 54.58.210.255 and HTTP_X_FORWARDED_FOR will populated with 1.25.32.51
So if any user visits your site with the proxy server then REMOTE_ADDRESS is the IP address of the machine which is actually making the request to your website, HTTP_VIA is the IP address of the proxy server and HTTP_X_FORWARDED_FOR is the IP address of the actual user who uses the proxy server.
Note: If request is made through proxy server the REMOTE_ADDR will be same as HTTP_VIA.
Very interesting your post!
Thanks Andrei !!!!!!
NIce!! thanks
Nice and very helpful post. It solved my confusion. Thanks.
thanx good article, playing with proxies at the moment and your article helped me
Just additional information the HTTP_VIA variable do not just display the proxy server’s IP address. It normally shows what proxy software is being used, including it’s version number.
Example:
eg: HTTP_VIA: HTTP/1.1 255-255-255-255.HINET-IP.hinet.net (Squid/1.3.28)</code?
In this sample the proxy domain and port are displayed, it also display the proxy software and version used.
i had a website to check the IP address and proxy ,and the site is in https ,in https http_via is not working and in http its working ,how to show http_via in https environment