如何使用 XMLHttpRequest 传递 php 会话 [英] How to pass php session with XMLHttpRequest

查看:29
本文介绍了如何使用 XMLHttpRequest 传递 php 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,我通过 XMLHttpRequest 从已经设置会话 cookie 的页面调用服务器上的 php 脚本.问题是我的页面调用的脚本为每个调用创建了一个新的 session_id,并且不使用现有的来存储我想要设置的信息.有什么解决办法吗?

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?

最好的问候,pbcoder

Best regards, pbcoder

推荐答案

您可能正在服务器端文件中重新生成会话 .... 您可以在此处发布检查会话的部分吗?您可以使用 session_id ( http://php.net/manual/en/function.session-id.php) 在 PHP 中.

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.

在你的 XHR 中设置 SID 变量

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

这篇关于如何使用 XMLHttpRequest 传递 php 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆