If I had a user logged onto my site, having his id stored in
$_SESSION, and from his browser he clicked a 'Save' button which would make an AJAX request to the server. Will his
$_SESSION and cookies be retained in this request, and can I safely rely on the id being present in the
The answer is yes:
Sessions are maintained server-side. As far as the server is concerned, there is no difference between an AJAX request and a regular page request. They are both HTTP requests, and they both contain cookie information in the header in the same way.
What you're really getting at is: are cookies sent to with the AJAX request? Assuming the AJAX request is to the same domain (or within the domain constraints of the cookie), the answer is yes. So AJAX requests back to the same server do retain the same session info (assuming the called scripts issue a session_start() as per any other PHP script wanting access to session information).