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.
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 18.104.22.168 ) >> Proxy (USA 22.214.171.124) >> http://www.xpertdeveloper.com
AS per above scenario REMOTE_ADDRESS will populated with 126.96.36.199, HTTP_VIA will populated with 188.8.131.52 and HTTP_X_FORWARDED_FOR will populated with 184.108.40.206
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.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash