0

Hi Guys I declared a variable session in php wordpress site, but after 5 minutes of no navigation it lost the value, but the session it's still active, and the session.gc_maxlifetime in php.ini is set to defaults 1440 seconds (24 minutes). here is my code:

public function __construct() { 

    echo '<script>console.log("0: '.session_status().'")</script>'; 

    if ( ( $_SESSION['logged'] != null ) && (isset($_SESSION['logged'])) )
    {

        self::$profile = $_SESSION['logged'];   
        self::$favoriteTeam = self::$profile->favorite_team;

        echo '<script>console.log("1: '.self::$profile->fb_user_id.'")</script>';   
        echo '<script>console.log("2: '.self::$profile->favorite_team.'")</script>';    
        echo '<script>console.log("3: '.self::$favoriteTeam.'")</script>';      

    } 

}


public function(){ $_SESSION['logged'] = self::$profile = $user;    }

UPDATE: I forgot to mention that this is a wordpress project and yes the content it's saved into session variable if i try to debug:

echo '<script>console.log("1: '. $_SESSION['logged'].'")</script>'; 
4

2 回答 2

1

这可能是因为 cookie 生命周期设置为低。检查此链接

也不要忘记session_start()

尝试不强制设置为 $user in ()

if (isset($user) || !isset(self::$profile)) {
  $_SESSION['logged'] = self::$profile = $user;  
}
于 2013-03-15T08:15:17.610 回答
1

在使用该值之前是否先开始会话

public function __construct() { 

    session_start();

    echo '<script>console.log("0: '.session_status().'")</script>'; 

    if ( ( $_SESSION['logged'] != null ) && (isset($_SESSION['logged'])) )
    {

        self::$profile = $_SESSION['logged'];   
        self::$favoriteTeam = self::$profile->favorite_team;

        echo '<script>console.log("1: '.self::$profile->fb_user_id.'")</script>';   
        echo '<script>console.log("2: '.self::$profile->favorite_team.'")</script>';    
        echo '<script>console.log("3: '.self::$favoriteTeam.'")</script>';      
    } 
}

public function()
{ 
        $_SESSION['logged'] = self::$profile = $user;    
}
于 2013-03-15T08:14:44.023 回答