在公眾平台開發中 為什麼在一個模組下的2個控制器中同一個session不能用
//網頁授權擷取使用者基本資料 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); }```
回複內容:
在公眾平台開發中 為什麼在一個模組下的2個控制器中同一個session不能用
//網頁授權擷取使用者基本資料 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); }```
session(null);
session(null); //已經把session清空了. 當然下面就拿不到了