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>';
Have you start the session first before you used that values
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;
}
This could be because the cookie lifetime is set to low. Check this link
Also don't forget session_start()
.
Try not forcing a set to $user in ()
:
if (isset($user) || !isset(self::$profile)) {
$_SESSION['logged'] = self::$profile = $user;
}