How to pass php session with XMLHttpRequest

╄→гoц情女王★ 提交于 2020-01-15 05:15:48

问题


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


回答1:


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();



回答2:


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(); ?>


来源:https://stackoverflow.com/questions/6981010/how-to-pass-php-session-with-xmlhttprequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!