I want to resume a session. So I'm passing session id and trying to resume session like so:
session_save_path($_SERVER["DOCUMENT_ROOT"].'/mysessions');
if(!empty($_POST['session_id'])) {
session_id($_POST['session_id']); // $_POST['session_id'] = "4dkwkeiugraqhfpeq745l2c2a1";
session_start();
}
$session_var = $_SESSION['property_name']; // <- null even though there was something there
ob_start();
var_dump($_SESSION);
$session_data = ob_get_clean(); // $session_data = NULL
I see that physical session file exists ' sess_4dkwkeiugraqhfpeq745l2c2a1
' in the session folder where I store my sessions. Three is data there. However, the session does not resume. After calling session_start()
, $_SESSION
variables are not there.
What am I misssing here?
What am I missing here?
That's hard to say. session_id()
is the correct function to change the session id, however the session_save_path()
might be a different one. So you think the session is on the disk, but it's the wrong directory.
Or even a different save handler, so not even saving to disk but into database.
Also inside your code I don't see any check to test if the $_SESSION
is actually empty or not, so it's not clear where you check that. You should test this directly after session_start()
so that you know if the data was loaded or not.
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.