I want to restore all PHP session variables from an earlier session using a value hashed and salted and then stored in a cookie. I use 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();
Of existing posts on stackoverflow, most on point is How to restore a PHP session? but it doesn't actually address retrieving sessions that have not been deleted by the server. So long as the sessions are still on the server, shouldn't I be able to reload them with these two lines of code?
session_id($storeResult);
session_Start();
Right now I see that the cookie is set but the session variables (e.g. $_SESSION['votes']) never are set. All I am doing is closing the browser and reopening, so the time after the initial session is minimal.
From prior postings, there doesn't seem to be a direct way to check whether a session with a particular id exists. Any other suggestions for troubleshooting this? Thank you.