When redis is used to save the session, that is, only session_id is used, isn't the actual value stored in the session? When {code...} is used to save the session, {code...} is used to save the session, that is, only session_id is used, and the actual value is not stored in the session?
// Obtain session_id $ sid = session_id (); \ Predis \ Autoloader: register (); $ a = new \ Predis \ Client (); $ a-> set ('Sid ', $ sid); $ a-> set ('uid', '123 ');
When getting the value
$ Sidfrompost = I ('post. sid '); \ Predis \ Autoloader: register (); $ a = new \ Predis \ Client (); $ sidfromredis = $ a-> get ('Sid '); if ($ sidfrompost! = $ Sidfromredis) {$ this-> ajaxReturn (array ("result" => "illegal access"); exit ;} else {$ this-> ajaxReturn (array ("uid" => $ a-> get ('uid'), "sid" => $ sidfromredis, "session" => session ()));}
Reply content:
When redis is used to save the session, that is, only session_id is used, isn't the actual value stored in the session?
// Obtain session_id $ sid = session_id (); \ Predis \ Autoloader: register (); $ a = new \ Predis \ Client (); $ a-> set ('Sid ', $ sid); $ a-> set ('uid', '123 ');
When getting the value
$ Sidfrompost = I ('post. sid '); \ Predis \ Autoloader: register (); $ a = new \ Predis \ Client (); $ sidfromredis = $ a-> get ('Sid '); if ($ sidfrompost! = $ Sidfromredis) {$ this-> ajaxReturn (array ("result" => "illegal access"); exit ;} else {$ this-> ajaxReturn (array ("uid" => $ a-> get ('uid'), "sid" => $ sidfromredis, "session" => session ()));}
You can set a get in this way to support cross-origin. you can get the best result. if cross-origin is used, your apsaradb for redis instance must enable the external port. to ensure security, set the redis login password.
In fact, you don't have to ask so many questions at once and make good use of the search. I Google to search for "ThinkPHP session redis". The first one is the CSDN blog article: Portal