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

tp框架中的session 问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:07:07
Original
1032 people have browsed it

在微信公众平台开发中 为什么在一个模块下的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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

回复内容:

在微信公众平台开发中 为什么在一个模块下的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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

<code>session(null);</code>
Copy after login

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

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template