不要AJAX请求保留PHP会话信息? [英] Do AJAX requests retain PHP Session info?

查看:155
本文介绍了不要AJAX请求保留PHP会话信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个用户登录到我的网站,有自己的ID存储在 $ _ SESSION ,并从他的浏览器,他点击了保存按钮,将成为一个AJAX请求发送到服务器。请问他的 $ _ SESSION 和饼干保留在这一请求,我可以放心地依靠ID为present在 $ _ SESSION

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 $_SESSION?

推荐答案

答案是肯定的:

会话保持服务器端。至于服务器而言,有一个AJAX请求和常规寻呼请求没有任何区别。它们都是HTTP请求,并且它们都包含在以相同的方式头cookie信息。

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.

从客户端,同样的饼干将总是被发送到服务器是否它是一个普通的请求或一个AJAX请求。 JavaScript的code并不需要做什么特别的事情,甚至要知道这种情况发生的,它只是工作一样它与常规的请求。

From the client side, the same cookies will always be sent to the server whether it's a regular request or an AJAX request. The Javascript code does not need to do anything special or even to be aware of this happening, it just works the same as it does with regular requests.

这篇关于不要AJAX请求保留PHP会话信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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