您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

使用redis储存session的时候,步骤是这样的吗

2025/10/4 12:19:20发布19次查看
使用redis来保存session的时候,也就是只使用session_id对吗,不在session里面真实存值?
//获取session_id $sid=session_id(); \predis\autoloader::register(); $a = new \predis\client(); $a->set('sid',$sid); $a->set('uid','100');

获取值的时候
$sidfrompost=i('post.sid'); \predis\autoloader::register(); $a = new \predis\client(); $sidfromredis=$a->get('sid'); if($sidfrompost!=$sidfromredis){ $this->ajaxreturn(array(result=>非法访问)); exit; }else{ $this->ajaxreturn(array(uid=>$a->get('uid'),sid=>$sidfromredis,session=>session())); }

回复内容: 使用redis来保存session的时候,也就是只使用session_id对吗,不在session里面真实存值?
//获取session_id $sid=session_id(); \predis\autoloader::register(); $a = new \predis\client(); $a->set('sid',$sid); $a->set('uid','100');

获取值的时候
$sidfrompost=i('post.sid'); \predis\autoloader::register(); $a = new \predis\client(); $sidfromredis=$a->get('sid'); if($sidfrompost!=$sidfromredis){ $this->ajaxreturn(array(result=>非法访问)); exit; }else{ $this->ajaxreturn(array(uid=>$a->get('uid'),sid=>$sidfromredis,session=>session())); }

可以这样做的一个set一个get支持跨域,你能拿到最好,跨域的话你的redis的就要开启外部端口,为了安全请你设置redis的登录密码
其实你没必要一下子问这么多问题,善用搜索,我google搜索“thinkphp session redis第一个就是csdn博客的文章:传送门
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product