Laravel 4 基于 IP 的用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16952773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 IP based users?
提问by Farzher
I'm not sure what the term for this is, but I want everyone who visits the site to have their IP entered in the users table so I can transparently keep track of them. It'd be nice if they could sign up normally if they want at some point too.
我不确定这是什么术语,但我希望访问该站点的每个人都将他们的 IP 输入到用户表中,以便我可以透明地跟踪他们。如果他们也想在某个时候正常注册,那就太好了。
Is there a proper way to do this in Laravel 4?
在 Laravel 4 中是否有正确的方法来做到这一点?
Edit: I want users to only be an IP, no username or password. When someone visits, if that IP exists, return that user object, if not, insert a new user based on their IP.
编辑:我希望用户只是一个 IP,没有用户名或密码。当有人访问时,如果该IP存在,则返回该用户对象,如果不存在,则根据其IP插入一个新用户。
回答by Antonio Carlos Ribeiro
One way of doing int is to put something like this on a file like your app/start/global.php:
执行 int 的一种方法是将类似的内容放在类似 app/start/global.php 的文件中:
if (Auth::check())
{
Auth::user()->ip_address = Request::getClientIp();
Auth::user()->save();
}
And, of course, you'll also need the ip_address column to be added to your users table;
而且,当然,您还需要将 ip_address 列添加到您的用户表中;