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.

About the Author: Avinash

Experienced full stack freelance web developer with a track record of producing excellent results for 11+ years. Excellent communication and collaboration skills, managing with a team of 20+ people. I’m motivated to make a positive impact on your revenue through the customer web portal development project.

7 Comments

  1. Andrei August 22, 2011 at 11:38 am - Reply

    Very interesting your post!

  2. megainfo August 24, 2011 at 2:55 pm - Reply

    NIce!! thanks

  3. Reazul September 8, 2011 at 9:37 pm - Reply

    Nice and very helpful post. It solved my confusion. Thanks.

  4. tvarkarastis December 5, 2011 at 10:06 pm - Reply

    thanx good article, playing with proxies at the moment and your article helped me

  5. Android VPN March 19, 2012 at 5:18 pm - Reply

    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.

  6. Justin jacob April 26, 2013 at 11:44 am - Reply

    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

Leave A Comment

FREE QUOTE

Do you need help with services? Request a free quote to get in touch.