Reputation: 25860
When creating a session and storing data into it, if the session id has not yet been returned to the client, then multiple calls from the client to the server will result in different data showing in the $_SESSION
object.
For example:
$_SESSION[ "status" ] = "started"
$_SESSION[ "status" ]
If step #2 had to create the session (session_start();
) but has not yet returned to the client, then step #4 will not see the new value in $_SESSION[ "status" ]
.
So I need to be able to check whether the client has a session id yet. How do I do this?
Checking session_id()
doesn't work, because if any code has called session_start()
, then I'll get a value returned even if the client hasn't yet received it in a response.
Upvotes: 0
Views: 99
Reputation: 37048
Before Client uses ajax to request a page: "/very_slow.php" the client probably opened a page with some HTML and Javascript, which makes the ajax request. Start the session there. Session ID will be sent to the client as HTTP header and will be used by xhr on step 1. It will guarantee session cookie for steps 1..4.
Upvotes: 2