skip to Main Content

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!

2

Answers


  1. Test session id

    if(!empty(session_id()){
        echo "Booo raczki ..."
    }
    

    And

    if(!empty($_SESSION['user_email'])){
       echo "Works ...."
    }
    

    Detect if PHP session exists

    Login or Signup to reply.
  2. you must have to start session before setting initial value for session e.g:

    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"; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search