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
[gads]
When any user visit your site without any proxy server in that case you can get the IP address using [code]REMOTE_ADDR[/code] server variable. So in that case [code]HTTP_X_FORWARDED_FOR[/code] and [code]HTTP_VIA[/code] will not be available.
Note: [code]HTTP_VIA[/code] and [code]HTTP_X_FORWARDED_FOR[/code] will be only populated if web server detects the use of the Proxy Server.
Now for understanding the [code]HTTP_VIA[/code] and [code]HTTP_X_FORWARDED_FOR[/code] 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.
[gads]
User( India 1.25.32.51 ) >> Proxy (USA 54.58.210.255) >> https://xpertdeveloper.com
AS per above scenario [code]REMOTE_ADDRESS[/code] will populated with 54.58.210.255, [code]HTTP_VIA[/code] will populated with 54.58.210.255 and [code]HTTP_X_FORWARDED_FOR[/code] will populated with 1.25.32.51
So if any user visits your site with the proxy server then [code]REMOTE_ADDRESS[/code] is the IP address of the machine which is actually making the request to your website, [code]HTTP_VIA[/code] is the IP address of the proxy server and [code]HTTP_X_FORWARDED_FOR[/code] is the IP address of the actual user who uses the proxy server.
[gads]
Note: If request is made through proxy server the [code]REMOTE_ADDR[/code] will be same as [code]HTTP_VIA[/code].
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