Kad*_*gun 5 php authentication session redirect laravel
我的 Laravel 会话存在身份验证问题。(之前是在同一个系统中运行的)
\n\n这是我的用户控制器
\n\npublic function postLogin()\n{\n $username = Input::get("username");\n $password = Input::get("password");\n $credentials = array\n (\n "username"=> $username,\n "password" => $password,\n );\n if (Auth::attempt($credentials)) \n {\n echo Auth::user()->username;\n exit();\n\n }\n else\n {\n return Redirect::to("user/login")->with("error_msg","Giri\xc5\x9f Ba\xc5\x9far\xc4\xb1s\xc4\xb1z! <br>L\xc3\xbctfen girdi\xc4\x9finiz bilgileri kontrol edip yeniden deneyin.");\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n它返回用户名..但是当我重定向页面时会话丢失。
\n\npublic function postLogin()\n{\n $username = Input::get("username");\n $password = Input::get("password");\n $credentials = array\n (\n "username"=> $username,\n "password" => $password,\n );\n if (Auth::attempt($credentials)) \n {\n return Redirect::to(\'check_login\');\n\n }\n else\n {\n return Redirect::to("user/login")->with("error_msg","Giri\xc5\x9f Ba\xc5\x9far\xc4\xb1s\xc4\xb1z! <br>L\xc3\xbctfen girdi\xc4\x9finiz bilgileri kontrol edip yeniden deneyin.");\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n还有我的路线:
\n\nRoute::get("check_login",function(){\n echo Auth::user()->username;\n});\nRun Code Online (Sandbox Code Playgroud)\n\n结果:
\n\nErrorException\nTrying to get property of non-object\necho Auth::user()->username;\nRun Code Online (Sandbox Code Playgroud)\n
检查您的路线的postLogin()功能。如果您使用 in UserController,它应该在下面的post方法中。
Route::post('login', array('uses' => 'UserController@postLogin'));
Run Code Online (Sandbox Code Playgroud)
您提供的功能和路线与我完美配合,但如果您想检查用户是否保存在会话中,请尝试这样。
if (Auth::check())
{
echo 'My user is logged in';
}
Run Code Online (Sandbox Code Playgroud)
如果您能提供您为此使用的所有路线,那就更好了。