In one of my PHP LOGIN page, I am using below code. I am using PHP Version : 7.3
Recently My Web Provider Migrated my server to a new server. After Migration, It was working fine. But after 12 hours, I see this error Now.
<?php
if(session_status() !== PHP_SESSION_ACTIVE)
{
// Finally, destroy the session.
session_start();
session_destroy();
unset($_SESSION);
session_regenerate_id(true);
session_start();
foreach ($_SESSION as $key=>$val)
echo $key." -".$val."<br/>";
}
?>
Error :
Warning: session_regenerate_id(): Cannot regenerate session id –
session is not active in /email/PHPMailer/index0.php on line 8Warning: session_start(): Cannot start session when headers already
sent in /email/PHPMailer/index0.php on line 9Warning: Invalid argument supplied for foreach() in
/email/PHPMailer/index0.php on line 10
2
Answers
You can’t regenerate an ID for a non-existent session because you destroyed it.Try switching lines 8 and 9 like this.
On my case the issue was related to the permission of the folder
/var/lib/php/session
that php uses to store session data. I fixed the issue by changing the permissions to777
:You can limit the permissions to
744
that also works fine.I hope this will help someone else.