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.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:20:26
Original
1541 people have browsed it

<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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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.

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