How to pass php session with XMLHttpRequest
The problem I've got is that I'm calling a php script on my server via XMLHttpRequest from a page that has already a session cookie set. The problem is that the script called by my page creates a new session_id for each call and does not use the existing one to store, the information I want to set, in it. Any solutions?
开发者_运维技巧Best regards, pbcoder
You're probably regenerating the session in your server side file .... can you post the part that checks the session here ? You can set a specific session id using session_id ( http://php.net/manual/en/function.session-id.php) in PHP.
set SID var in your XHR
$id_from_xhr_get_or_post_var=$_GET["SID"]; // or $_POST["SID"]; if you're using post
session_id($id_from_xhr_get_or_post_var);
session_name("your_session_name");
session_start();
You can store the old id in a hidden form field. It is then sent along with the rest of your XHR form data to the AJAX handling script.
<input type='hidden' name='oldsession' value='<?php echo session_id(); ?>
精彩评论