Home >Backend Development >PHP Tutorial >PHP+redis implements session sharing
The content of this article is about the realization of session sharing with PHP redis. It has a certain reference value. Now I share it with you. Friends in need can refer to it
This article mainly talks about how to use PHP redis implements session sharing. As for its principle, I won’t go into details here. Friends who need it can Baidu by themselves. Here we mainly talk about how to implement it.
#1. In order for different domain names to access the same SESSION_ID, set the domain to be unified here. Modify php.ini and change the default configuration to session.cookie_domain=".test.com".
Modify ".test.com" here according to your own needs.
#2. In order to make the data accessible on different websites, we choose to store the session in redis. Modify php.ini and change the default configuration to
session.save_handler=redis,
session.save_path="tcp://192.168.0.120:6379",
3. After the configuration is completed, write a php file and set the session in it. After running, a key will appear in redis, as follows:
At this point, even if the session is set successfully, you can use $_SESSION to read the value just set.
Note: You may encounter redis connection problems in the middle, just turn off the redis protection mode.
Related recommendations:
A simple example sharing of PHP redis
Ask for ideas on implementing task queues in PHP Redis
The above is the detailed content of PHP+redis implements session sharing. For more information, please follow other related articles on the PHP Chinese website!