This article mainly introduces the laravel5.6 and thinkphp3.2 use Redis shared session of the scheme, has a certain reference value, now share to everyone, the need for friends can refer to
In the actual project, the historical Project uses thinkphp3.2 development, now needs to update the function, updates the function part, intends to use the laravel5.6 to develop.
Problem description
There are several key issues that need to be addressed, one of which is the issue of user authentication. That is, when system 1 is logged in, System 2 automatically recognizes its login information. That is, the essence needs to be solved: Laravel and thiniphp share session problems.
Program Design
Session is stored using Redis. thinkphp and Laravel access Redis, which automatically acquires authenticated user information stored in Redis based on the same cookie.
Solution Solutions
thinkphp Turn on Redis support
thinkphp3.2 does not have redis support for the integrated session, at this point we use the settings in PHP to turn it on. In index.php, we add the following two lines of statements:
Ini_set ("Session.save_handler", "Redis"), Ini_set ("Session.save_path", "tcp://redis:6379");
You can also add it to the config.php configuration file
At this point, the thinkphp is stored as a prefix when the session is stored in phpredis_session.
Laravel Open Redis
Laravel the way to open Redis is relatively slightly more complicated. For specific information, you need to refer to the official documentation using composer to install Predis and configure it.
Laravel get thinkphp's session
Since Laravel completely deprecated the built-in session of PHP. So there's no way we can get any information from $_session (you'll even get a variable undefined error). Because the Laravel cookie is processed by encryption. Therefore, we also cannot use Laravel's own cookie to obtain cookie information.
The concrete implementation of the idea is:
1 get the native cookie.
2 Phpredis_session to form key
3 using Redis to get the value stored directly in key
... use Illuminate\support\facades\redis; .. $cookie = $_cookie[' Phpsessid '); $session = Redis::get (' phpredis_session: '. $cookie);
This $session is the session value in the thinkphp system.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!