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.

Subscribe

  • follow us in feedly


Tagged , , .

Updated: 2011-08-11

Phil LaNasa