Rails:获取客户端IP地址 [英] Rails: Get Client IP address
本文介绍了Rails:获取客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Rails中,获取连接到服务器的客户端ip地址的最佳方法是什么?
In Rails, what's the best way to get the ip address of the client connecting to the server?
以下是我找到的两种方法:
Here are two ways I've found:
request.remote_ip
request.env['HTTP_X_REAL_IP']
推荐答案
我只会使用简单且有效的request.remote_ip
.有什么理由需要其他方法吗?
I would just use the request.remote_ip
that's simple and it works. Any reason you need another method?
请参阅:在本地Rails开发环境中获取真实IP地址 对于其他一些事情,您可以使用客户端服务器ip进行.
See: Get real IP address in local Rails development environment for some other things you can do with client server ip's.
这篇关于Rails:获取客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文