Topic: Retrieving IP address of client machine??

Hi,

I am developing a web application, as part of it , I need to know the IP address of client machine(each logged in user's machine IP address).

Can any body tell me how to retrieve the IP address??

Thanks..

Re: Retrieving IP address of client machine??

request.remote_addr

Re: Retrieving IP address of client machine??

Or try:

request.remote_ip

You'll need to call this in the controller, not the model. If the model needs access to it you'll have to pass it from the controller.

Railscasts - Free Ruby on Rails Screencasts

Re: Retrieving IP address of client machine??

Or if you are using apache in front of a mongrel, then remote_ip will return the source address of the request, which in this case will be local host because the Apache web server is making the request.

The simple handling is to do something like this in your controller:

@remote_ip = request.env["HTTP_X_FORWARDED_FOR"]

Regards

Mikel

Re: Retrieving IP address of client machine??

How do you get the REMOTE_USER var from apache to mongrel?