If you use Redis to store the Session, you cannot delete it if you set only one value.

Source: Internet
Author: User
, Executing unset ($ _ SESSION [& #039; name & #039;]) cannot be deleted. Only when there are multiple sessions and the name is not in the first place can it be deleted, the first session cannot be deleted. Are you aware of this situation? I have tried both online and offline and cannot solve the problem...

, Unset ($ _ SESSION ['name']) cannot be deleted;
Only sessions with names not in the first place can be deleted. sessions with names not in the first place cannot be deleted. Are you aware of this situation?

I tried both online and offline and cannot solve the problem.

I found the problem because I changed the session_set_save_handler () method:


  _ Cache = $ cache; $ this-> _ lifetime = ini_get ('session. gc_maxlifetime '); session_set_save_handler (array ($ this,' _ open'), array ($ this, '_ close'), array ($ this,' _ read '), array ($ this, '_ write'), array ($ this,' _ destroy '), array ($ this,' _ gc '));} // _ open public function _ open ($ savePath, $ name) {return true;} // _ close public function _ close () {$ this-> _ gc ($ this-> _ lifetime); return true;} // _ read pu Blic function _ read ($ id) {$ res = $ this-> _ cache-> get (self: CACHE_KEY. $ id, FALSE); return $ res? $ Res: '';} // _ write public function _ write ($ id, $ value) {if ($ value) {$ flag = $ this-> _ cache-> set (self: CACHE_KEY. $ id, $ value, intval ($ this-> _ lifetime), FALSE); return $ flag;} else {return FALSE ;}} // _ destroy public function _ destroy ($ id) {$ flag = $ this-> _ cache-> delete (self: CACHE_KEY. $ id); return $ flag;} // _ gc public function _ gc ($ lifetime ){}}

Call:

$ Cache = load_cache (); // returns the Redis object $ handle = new Session_Redis ($ cache );

Is there any problem with the code?

Reply content:

, Unset ($ _ SESSION ['name']) cannot be deleted;
Only sessions with names not in the first place can be deleted. sessions with names not in the first place cannot be deleted. Are you aware of this situation?

I tried both online and offline and cannot solve the problem.

I found the problem because I changed the session_set_save_handler () method:


  _ Cache = $ cache; $ this-> _ lifetime = ini_get ('session. gc_maxlifetime '); session_set_save_handler (array ($ this,' _ open'), array ($ this, '_ close'), array ($ this,' _ read '), array ($ this, '_ write'), array ($ this,' _ destroy '), array ($ this,' _ gc '));} // _ open public function _ open ($ savePath, $ name) {return true;} // _ close public function _ close () {$ this-> _ gc ($ this-> _ lifetime); return true;} // _ read pu Blic function _ read ($ id) {$ res = $ this-> _ cache-> get (self: CACHE_KEY. $ id, FALSE); return $ res? $ Res: '';} // _ write public function _ write ($ id, $ value) {if ($ value) {$ flag = $ this-> _ cache-> set (self: CACHE_KEY. $ id, $ value, intval ($ this-> _ lifetime), FALSE); return $ flag;} else {return FALSE ;}} // _ destroy public function _ destroy ($ id) {$ flag = $ this-> _ cache-> delete (self: CACHE_KEY. $ id); return $ flag;} // _ gc public function _ gc ($ lifetime ){}}

Call:

$ Cache = load_cache (); // returns the Redis object $ handle = new Session_Redis ($ cache );

Is there any problem with the code?

You have never encountered this problem. Check whether it has been re-generated. You can assign a value to $ _ SESSION ['name'] After unset ($ _ SESSION ['name.

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.