Home >Backend Development >PHP Tutorial >tp框架中的session 问题

tp框架中的session 问题

WBOY
WBOYOriginal
2016-06-06 20:07:07999browse

在微信公众平台开发中 为什么在一个模块下的2个控制器中同一个session不能用

<code>//网页授权获取用户基本信息
    public function webUsers(){
        $token=session('token');
          $wechatAuth=new WechatAuth($this->appId,$this->appSecret,$token);
         //$wechatAuth=$this->wechatAuth;
        
        if($_GET['iscode']){
            $url="http://hdzs.zhed.com/index.php/Activity/index";
            $result=$wechatAuth->getRequestCodeurl($url);
            header("Location:{$result}");
            
        }else 
        if($_GET['code']){
            
            header('Content-type:text/html;charset=utf-8');
            
            $users=$wechatAuth->getAccessToken('code',$_GET['code']);//疑惑语句
            
            $User=M("User");//实例化user对象
            $openid=$users['openid'];
            session('openid',"$openid");//将用户的openid存入session中</code>
<code>public function users($wechat,$data){
    
        $openid=$data['FromUserName'];
        //session(null);
        // session('openid',"$openid");
        //$wechatAuth=$this->wechatAuth;//实例化 $wechatAuth对象
        ///$user=$wechatAuth->UserInfo($openid);
        $text="你的用户名是:". session('openid');
        $this->logger("发送用户消息".$text);
        //$wechat->replyText($text);
    }```</code>

回复内容:

在微信公众平台开发中 为什么在一个模块下的2个控制器中同一个session不能用

<code>//网页授权获取用户基本信息
    public function webUsers(){
        $token=session('token');
          $wechatAuth=new WechatAuth($this->appId,$this->appSecret,$token);
         //$wechatAuth=$this->wechatAuth;
        
        if($_GET['iscode']){
            $url="http://hdzs.zhed.com/index.php/Activity/index";
            $result=$wechatAuth->getRequestCodeurl($url);
            header("Location:{$result}");
            
        }else 
        if($_GET['code']){
            
            header('Content-type:text/html;charset=utf-8');
            
            $users=$wechatAuth->getAccessToken('code',$_GET['code']);//疑惑语句
            
            $User=M("User");//实例化user对象
            $openid=$users['openid'];
            session('openid',"$openid");//将用户的openid存入session中</code>
<code>public function users($wechat,$data){
    
        $openid=$data['FromUserName'];
        //session(null);
        // session('openid',"$openid");
        //$wechatAuth=$this->wechatAuth;//实例化 $wechatAuth对象
        ///$user=$wechatAuth->UserInfo($openid);
        $text="你的用户名是:". session('openid');
        $this->logger("发送用户消息".$text);
        //$wechat->replyText($text);
    }```</code>

<code>session(null);</code>

session(null); //已经把session清空了. 当然下面就拿不到了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn