skip to Main Content

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 8

Warning: session_start(): Cannot start session when headers already
sent in /email/PHPMailer/index0.php on line 9

Warning: Invalid argument supplied for foreach() in
/email/PHPMailer/index0.php on line 10

2

Answers


  1. You can’t regenerate an ID for a non-existent session because you destroyed it.Try switching lines 8 and 9 like this.

    if(session_status() !== PHP_SESSION_ACTIVE)
    { 
    // Finally, destroy the session.
       session_start(); 
       session_destroy();
       unset($_SESSION);
       session_start(); 
       session_regenerate_id(true);
       foreach ($_SESSION as $key=>$val)
          echo $key." -".$val."<br/>";    
    }
    
    Login or Signup to reply.
  2. 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 to 777:

    chmod -R 777 /var/lib/php/session
    

    You can limit the permissions to 744 that also works fine.

    I hope this will help someone else.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search