Laravel5.2 how to delete a session.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.