简体   繁体   中英

Session not starting in PHP 7.4 but the same code works in PHP 7.1 without doing any change

backend.php file: where following session variables are being set

    $_SESSION['user_id'] = $user_id;
    $_SESSION['user_email'] = $user_email;

Next: As I can verify in the directory /var/cpanel/php/sessions/ea-php74 the session files are getting created. After this the session suppose to be read and understood by the website frontend index.php file and for that below is the index.php code

session_start();
if(isset($_SESSION['user_email'])){

update session variable e.g., 
$user_email = $_SESSION['user_email'];

}else{
    echo "session not set"; 
}

but somehow the session_start() or if(isset($_SESSION['user_email'])) is not functioning hence the flow always go to else condition and it ends with "session not set"

Note: The php.ini file contains session.save_path = "/var/cpanel/php/sessions/ea-php74"

Please suggest!

Note that this same question was deleted by "Machavity " citing that it is already answered: Detect if PHP session exists but those suggested questions are not working for my case and I had to re-ask the question again freshly here. I will request you to stop this unfair practise or else put a notice that only experts and biggies like "Machavity " has right to remain in this forum, let me know such that I will better walk away from this forum.

you must have to start session before setting initial value for session eg:

session_start();
$_SESSION['user_id'] = $user_id;
$_SESSION['user_email'] = $user_email;

and then you can read or edit session values:

if(isset($_SESSION['user_email'])){

echo "session is set";

}else{
    echo "session not set"; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM