Home >Backend Development >PHP Tutorial >When developing TP, setting session in one method cannot get the value in other methods.

When developing TP, setting session in one method cannot get the value in other methods.

WBOY
WBOYOriginal
2016-08-04 09:20:261491browse

<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?

Reply content:

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

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