Results 1 to 2 of 2

Thread: Why use HTTP_X_FORWARDED_FOR?

  1. #1
    Join Date
    Dec 2009
    Posts
    9

    Question Why use HTTP_X_FORWARDED_FOR?

    Hi, I was wondering why people use $_SERVER['HTTP_X_FORWARDED_FOR'] in PHP for getting the user's IP address. If you look at the page http://roshanbh.com.np/2007/12/getti...ss-in-php.html (there's many others that are similar), they recommend using HTTP_X_FORWARDED_FOR before REMOTE_ADDR. I can easily modify my http headers to trick it into thinking I'm from any IP address. Anyone know why people use it then?

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    Quote Originally Posted by smengler View Post
    Hi, I was wondering why people use $_SERVER['HTTP_X_FORWARDED_FOR'] in PHP for getting the user's IP address. If you look at the page http://roshanbh.com.np/2007/12/getti...ss-in-php.html (there's many others that are similar), they recommend using HTTP_X_FORWARDED_FOR before REMOTE_ADDR. I can easily modify my http headers to trick it into thinking I'm from any IP address. Anyone know why people use it then?
    You could, but there are multiple ways of identifying a client. The basics include IP address, user agent, operating system, cookies etc. As mentioned in the link you posted, proxy servers may be used to mask a user's ip, while this is true, the new IP isn't wrong, the connection is still coming from the proxy server. HTTP_X_FORWARDED_FOR may contain the IP of the originating client and all the proxy servers, or it may not. It is just an added piece of information that shouldn't be treated as fact.

    "A web server should log BOTH the request's source IP and the X-Forwarded-For header information for completeness." - Wikipedia
    Last edited by Alan; 06 Feb 2010 at 04:51 PM.
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •