最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass php session with XMLHttpRequest - Stack Overflow

programmeradmin7浏览0评论

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

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

Share Improve this question asked Aug 8, 2011 at 10:48 Pascal BayerPascal Bayer 2,6138 gold badges33 silver badges51 bronze badges 1
  • 1 How is your session id transported from client to server normally? By a cookie or as a query parameter or both? – hakre Commented Aug 8, 2011 at 10:54
Add a ment  | 

2 Answers 2

Reset to default 4

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/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(); ?>
发布评论

评论列表(0)

  1. 暂无评论