0

I have implemented PHP sessions on WordPress custom pages using a custom templates. I have used session like below:

session_start();
$_SESSION["uuid"] = $uuid;
$_SESSION["email"] = $email;
$_SESSION["mdmId"] = $network_id;

Everything working perfectly fine on the whole website. Now, by default, the current session timeout is something around 20 minutes maybe. So, we want to increase session timeout up to one hour. So what do we need to do to increase the session timeout period?

I have increased session timeout duration up to one hour using the below code, it's working on localhost, but not working on WordPress VIP hosting server platform.

session_start();
$_SESSION['login_time'] = time();

if(time()-$_SESSION['login_time']>=3600)
{
  session_destroy();
  header('location:/nexplanontraining/ctp-resources/login/');
  die();
  //redirect if the page is inactive for 60 minutes
}
else{
  $_SESSION['login_time'] = time();

THE PAGE TEMPLATE GOES HERE
}
Gopal
  • 3
  • 4
  • 1
    Does this answer your question? [How do I expire a PHP session after 30 minutes?](https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – mitkosoft Apr 08 '22 at 08:19

1 Answers1

0

WordPress sessions are programmed to timeout after 48 hours. This is the code that I added to keep user logged in for 2 weeks on my website:

add_filter(‘auth_cookie_expiration’, 

‘keep_me_logged_in_for_2_week’ );

function keep_me_logged_in_for_2_week( $expirein ) {

return WEEK_IN_SECONDS; // 2 week in seconds

}