Laravel Session Sharing issues

Source: Internet
Author: User
Little brother in the development process encountered laravel above not understand the place, may be recently only to start using this framework reason it.
For Laravel session of the problem is not very understanding, hope to have a study laravel framework of friends can help answer my questions,
Next Brother development Project situation bar.

The first use of Laravel to establish the User Center system, and then through the session stored in the Redis method and other "application", for example: Article System (also laravel for the framework development) to the user's login information sharing synchronization.

Here's the problem:

    1. I found two laravel (5.1 versions) of the session between the read and write (I do not know the session ID is generated mechanism and logic) generated by the session with the app/config inside the file. Two items change the app/config inside the configuration file will cause the session user information can not be read successfully.

    2. Since the company's projects are not all laravel (at least in the short term) that assumes that some projects use a framework such as TP or CI, how can these frameworks succeed in acquiring Laravel's session?

Look forward to expert guidance, thank you

Reply content:

Little brother in the development process encountered laravel above not understand the place, may be recently only to start using this framework reason it.
For Laravel session of the problem is not very understanding, hope to have a study laravel framework of friends can help answer my questions,
Next Brother development Project situation bar.

The first use of Laravel to establish the User Center system, and then through the session stored in the Redis method and other "application", for example: Article System (also laravel for the framework development) to the user's login information sharing synchronization.

Here's the problem:

    1. I found two laravel (5.1 versions) of the session between the read and write (I do not know the session ID is generated mechanism and logic) generated by the session with the app/config inside the file. Two items change the app/config inside the configuration file will cause the session user information can not be read successfully.

    2. Since the company's projects are not all laravel (at least in the short term) that assumes that some projects use a framework such as TP or CI, how can these frameworks succeed in acquiring Laravel's session?

Look forward to expert guidance, thank you

OK, here I come.
Here is a brief introduction to the session mechanism of Laravel (now learn to sell, thank you for the opportunity), the following is an unencrypted file mode example.
How is the laravel stored and read?
First say storage,
We can see that the \Illuminate\Session\SessionManager createNativeDriver class is called in FileSessionHandler .
The location of the write is in the PATH\storage\framework\sessions directory, with the ID as the file name, and this ID is read from the user's cookie.
The write does not introduce, because the main question wants to read, I This first briefly introduces how to read the data of the session in the file.

We look at \Illumiate\Session\Store the loadSession method that has a call$this->readFromHandler()

The function is defined as follows:

 protected function readFromHandler()    {        $data = $this->handler->read($this->getId());        if ($data) {            $data = @unserialize($this->prepareForUnserialize($data));            if ($data !== false && $data !== null && is_array($data)) {                return $data;            }        }        return [];    }

We know that if it's file then FileSessionHandler it's read very simple.

public function read($sessionId)    {        if ($this->files->exists($path = $this->path.'/'.$sessionId)) {            return $this->files->get($path);        }        return '';    }

is to read the data from the file, finished.

So in fact, let's look at the serialized session file below my directory.

a:5:{s:6:"_token";s:40:"kHhZ458I4t5y2M3CMsAvLNrqy4GOOgCkRiRbhiD5";s:9:"_previous";a:1:{s:3:"url";s:16:"http://localhost";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:38:"login_82e5d2c56bdd0811318f0cf078b78bfc";i:1;s:9:"_sf2_meta";a:3:{s:1:"u";i:1442888664;s:1:"c";i:1442887470;s:1:"l";s:1:"0";}}

Try to unserialize and get the results.

Knowing the location and algorithm of the Laravel store, you can read it into your own framework along with the handler read method (which, of course, requires an adapter to be converted).

Have questions Welcome to Exchange ~

Multi-application sharing as a hair without rest?

Because the author of the Laravel, feel that the PHP system session is not elegant, so, a self-made one,
Of course, it is not compatible with PHP native session,
If you really want multiple project sharing (not just laravel), there are two ways to
One is to make a laravel-session compatible class for other applications, but this cost is a bit high.
Another kind, is the business inside uses to the session place, abandoned uses Laravel session,
Use PHP native session (Session_Start () to start),
The data is shared so all PHP can read it.

Different system unified login should design a set of rules and mechanisms, in fact, and larval no relationship

Using oauth2.0

  • 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.