The session problem in TP frame

Source: Internet
Author: User
Keywords Php
Tags openid
Why the same session cannot be used in 2 controllers under a module in the development of public platform

//网页授权获取用户基本信息    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中
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);    }```

Reply content:

Why the same session cannot be used in 2 controllers under a module in the development of public platform

 //Web page authorization to get user basic information 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 ');//interrogative statement $User =m ("user");//Instantiate user            Like $openid = $users [' OpenID ']; Session (' OpenID ', ' $openid ');//The user's OpenID is credited to the session  
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);    }```

session(null);

session (NULL); The session has been emptied. Of course, I can't get it down here.

  • 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.