我想在Laravel 4中获得会话的ID
在Laravel 3中,它有点hacky,但可能使用此代码:
$session_id = Session::$instance->session['id'];
Run Code Online (Sandbox Code Playgroud)
但我无法在Laravel 4中解决这个问题...引用该Session::$instance对象会引发错误:
访问未声明的静态属性:Illuminate\Support\Facades\Session :: $ instance
试过:
$session_id = Session::get('id');
Run Code Online (Sandbox Code Playgroud)
但无济于事..任何想法?
所以我试图阻止已经登录的用户在不同的浏览器或另一台计算机上登录。我想我需要添加一个 IP 地址限制,但我不确定这会如何工作。
这是我的create_users_table.php迁移文件
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password');
$table->timestamp('last_login');
$table->boolean('isActive')->default(true);
$table->rememberToken();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
我还认为我需要在RedirectIfAuthenticated Middleware 类中创建一个限制。
所以,这是我的RedirectIfAuthenticated.php 类
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/');
}
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
什么是最佳解决方案,并防止已经登录的用户从另一台计算机登录?提前致谢 !!!