Recover php session with saved session id?

I want to restore all PHP session variables from an earlier session using a hashed and salted value and then stored in a cookie. I am using this value to retrieve the old session id and then try to load that session.

if(isset($_COOKIE['user']))
    {
        $user = sanitizeString($_COOKIE['user']);   
        $result = queryMySQL("SELECT sessionID FROM cookie WHERE user='$user'");

             if ($result->num_rows == 1)
                {     
                    $row = $result->fetch_array(MYSQLI_ASSOC);              
                    //echo $row['sessionID'];
                     $storeResult=$row['sessionID'];
                     session_id($storeResult);
                }     
    }

session_start();

      

From existing posts on stackoverflow, most on point How to restore a PHP session? but it doesn't really refer to getting sessions that the server hasn't deleted. As long as the sessions are still on the server, shouldn't I reload them with these two lines of code?

session_id($storeResult);
session_Start();

      

Right now I can see that the cookie is set, but the session variables (like $ _SESSION ['votes']) are never set. All I do is close the browser and reopen it, so the time after the initial session is minimal.

From previous posts, there doesn't seem to be a direct way to check if a session with a specific ID exists. Any other suggestions for troubleshooting? Thank.

+3


source to share





All Articles