What should I do if the laravel framework does not store cookies on the client?

Source: Internet
Author: User
In laravel framework, if there is no cookie Mechanism on the client side, the user State can only be maintained by the sid. How can this problem be solved to ensure that the session works normally? I now get a sidsession_id ($ sid) directly at the beginning of the project. It can be processed, but it is really bad. headache... in laravel framework, if there is no cookie Mechanism on the client side, the user status can only be maintained by sid. in this case, how can we ensure that the session works properly?

Now, the project gets a sid session_id ($ sid) directly at the top of the project. It can be processed, but it is really bad.

For example, to create an api for a mobile app, you may need to log on to the app. however, my android programmers say they do not want to make cookies ). there is no way to pass the sid to them after login as a cookie, and then use the sid to enable session session_id ($ sid) each time a request is sent.

Is there a more elegant way to solve this problem? This is really ugly, and may cause other problems.

Reply content:

In laravel framework, if there is no cookie Mechanism on the client side, the user State can only be maintained by the sid. How can this problem be solved to ensure that the session works normally?

Now, the project gets a sid session_id ($ sid) directly at the top of the project. It can be processed, but it is really bad.

For example, to create an api for a mobile app, you may need to log on to the app. however, my android programmers say they do not want to make cookies ). there is no way to pass the sid to them after login as a cookie, and then use the sid to enable session session_id ($ sid) each time a request is sent.

Is there a more elegant way to solve this problem? This is really ugly, and may cause other problems.

Write a BaseController. php


  

Then the Controller inherits the BaseController.

 BeforeFilter ('@ filterAuth');} public function filterAuth ($ route, $ request) {$ user = Auth: user (); if (is_null ($ user )) {// return Redirect: guest ('user/login');} else {// logged on }}

Remember to set session_id after each requestSession::getId()Register it in the template or attach it to the URL

Laravel sessions provide multiple storage methods. If cookies are not supported locally, they can be stored on the server-side database.

Set 'driver '=> 'database' in app/config/session. php.
Add a session database to migrate. php artisan session: table

Cookies are also supported on mobile phones. Why not? Is it a wap site --#

URL global parameters --#

Ask them to refer to the source code of the open-source Chinese Android client, which contains the method for saving cookies.

PS: If you remember correctly, it should be inNet. oschina. app. api. ApiClientIn this class.

PS2:

However, my android programmers say they do not want to make cookies ).

What is the situation of this android programmer? I can't say I can't do it after I graduated, right?

You can use token in the form of a token to verify that a token is not logged on in laravel. After logging on, the token is sent to the client, then, the client adds a token to the header for access in future operations. Of course, this method is best used under https.

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.