Remote Host Address returns 127.0.0.1

So you're trying to track your users IP for one reason or another, but a glimpse at the REMOTE_ADDR server variable always returns localhost or 127.0.0.1.

Chances are, the reason this is happening is because your application server is running behind a web server such as Apache or IIS (as such is the case with Zope and other servers).

Because the application server is being forwarded requests from your web server, the REMOTE_ADDR variable will contain the localhost IP of 127.0.0.1.

Often times, these application servers offer another variable called HTTP_X_FORWARDED_FOR or similar. Try reading this variable instead, to see it is available and in fact carries the actual remote user's IP address.

Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs


Tagged , , .

Updated: 2011-08-11

Phil LaNasa follow us in feedly