Home >Backend Development >PHP Tutorial >When developing TP, setting session in one method cannot get the value in other methods.
<code>public function get_user_id(){ $user_id=$_POST['user_id'];//用户id //domain('xldios.zhekd.com'); //session(array('name'=>'user_id','domain'=>'xldios.zhekd.com','path'=>'/home/session/')); session('user_id',"$user_id"); $text="userid=".$user_id."session=".session('user_id')."sessi目录".session_save_path(); $this->logger($text); }</code>
In the above method, the session can be obtained by retrieving the value immediately after assigning a value to the session
But in the same controller, it cannot be obtained by other methods
What's going on?
<code>public function get_user_id(){ $user_id=$_POST['user_id'];//用户id //domain('xldios.zhekd.com'); //session(array('name'=>'user_id','domain'=>'xldios.zhekd.com','path'=>'/home/session/')); session('user_id',"$user_id"); $text="userid=".$user_id."session=".session('user_id')."sessi目录".session_save_path(); $this->logger($text); }</code>
In the above method, the session can be obtained by retrieving the value immediately after assigning a value to the session
But in the same controller, it cannot be obtained by other methods
What's going on?
<code>session('user_id')</code>
You can get it this way, what’s the problem?
Execute this method first and then call other methods in the controller to get it?
The code is not posted in its entirety and is unclear.