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.