When the user logs out, ajax calls the $ request-& amp; gt; session ()-& amp; gt; put (& #039; user & #039;, & #039; value & #039;); $ request-& amp; gt; session ()-& amp; gt; forget (& #039; user & #039;); then jump to the login page, but find that the session data obtained after the jump is still... when the user logs out, ajax calls the $ request-> session ()-> put ('user', 'value') set when deleting the session logon ');
$ Request-> session ()-> forget ('user') is used, and the login page is displayed.
However, it is found that the session data obtained after the jump is still in the session status before the deletion, so the logon status is maintained. Is it my usage error?
The following is the ajax call method:
Public function logout (Request $ request) {if ($ request-> session ()-> has ('user') {$ is_forgotten = $ request-> session () -> forget ('user'); if ($ is_forgotten = null) echo json_encode (['result' => 1]); exit ;} echo json_encode (['result' => 0, 'msg '=> 'logout failed']); exit ;}
The following Code assigns a value to the session user upon Logon:
Public function valid (Request $ request) {$ r = $ request-> all (); $ validator = Validator: make ($ r, ['username' => 'bail | required', 'Password' => 'bail | required | integer ',]); if ($ validator-> fails ()) {return redirect ('admin/login')-> withErrors ($ validator)-> withInput ();} $ where = ['name' => $ r ['username'], 'pwd' => md5 ($ r ['Password']),]; $ hasExists = AdminModel:: hasExists ($ where); if (null! ==$ HasExists) {$ request-> session ()-> put ('user', json_encode (['name' => $ r ['username']); return redirect ('admin');} else {return redirect ('admin/login')-> with ('hasexists', 'username or password error ');}}
Reply content:
When the user logs out, ajax calls the $ request-> session ()-> put ('user', 'value') set when deleting the session logon ');
$ Request-> session ()-> forget ('user') is used, and the login page is displayed.
However, it is found that the session data obtained after the jump is still in the session status before the deletion, so the logon status is maintained. Is it my usage error?
The following is the ajax call method:
Public function logout (Request $ request) {if ($ request-> session ()-> has ('user') {$ is_forgotten = $ request-> session () -> forget ('user'); if ($ is_forgotten = null) echo json_encode (['result' => 1]); exit ;} echo json_encode (['result' => 0, 'msg '=> 'logout failed']); exit ;}
The following Code assigns a value to the session user upon Logon:
Public function valid (Request $ request) {$ r = $ request-> all (); $ validator = Validator: make ($ r, ['username' => 'bail | required', 'Password' => 'bail | required | integer ',]); if ($ validator-> fails ()) {return redirect ('admin/login')-> withErrors ($ validator)-> withInput ();} $ where = ['name' => $ r ['username'], 'pwd' => md5 ($ r ['Password']),]; $ hasExists = AdminModel:: hasExists ($ where); if (null! ==$ HasExists) {$ request-> session ()-> put ('user', json_encode (['name' => $ r ['username']); return redirect ('admin');} else {return redirect ('admin/login')-> with ('hasexists', 'username or password error ');}}
It is recommended that you understand Larave's Session mechanism. If your code has exit, you 'd better set the Session: save () before it.