在 PHP $_SESSION 中存储数据不安全吗?
根据我的理解,PHP 进程的行为并不像应用程序服务器进程。因此,执行脚本后,PHP 进程不会保留任何用户特定数据。相反,它将它们存储在用户的 cookie 中。因此,我们在 $_SESSSION
中存储的任何内容都会进入 cookie。这是真的吗?如果是,那么它们是以明文形式存储的还是进行了某种编码或加密?
As per my understanding, PHP processes doesn't behave as application server process. So, after the execution of a script the PHP process retains no user specific data. It instead stores them in the user's cookie. So whatever we store in $_SESSSION
goes into cookies. Is this true? If yes then are they stored in clear text or some encoding or encryption is done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,会话 cookie 中唯一包含的是会话 ID——一个随机的字母数字字符串。所有会话数据都存储在服务器上的一个文件中(使用默认会话处理程序,尽管您可以覆盖以将数据存储在任何地方/任何您想要的方式)。
No, the only thing that goes into the session cookie is the ID of the session - a random alphanumeric string. All the session data is stored on the server in a file (using the default session handler, though you can override to store the data anywhere/any way you want).
不,那不是真的。会话 cookie 中仅存储会话 ID。会话数据全部存储在服务器端(尽管默认情况下以纯文本形式)。
No, that is not true. Only the session's ID is stored in the session cookie. The session data is all stored server-side (albeit in plain text, by default).
存储在客户端计算机上的“cookie”是会话 ID。 “会话”本身驻留在服务器上。当在会话期间请求页面时,会话 ID 会附加到查询字符串中,这让服务器知道要为此请求加载哪个会话。
除非会话 ID 被盗(并且会话被“劫持”),否则会话是安全的。您可以通过在会话中存储创建会话的 IP 地址和用户代理字符串并将它们与每次页面访问的请求 IP 地址和用户代理字符串进行比较来防止这种情况(在某种程度上)。请记住,这些依赖于 HTTP 标头并且可能被欺骗。
The 'cookie' that is stored on a client computer is a session id. The 'session' itself resides on the server. When a page is requested during a session, the session id is appended to the query string which lets the server know what session to load for this request.
Unless the session id is stolen (and the session 'hijacked'), sessions are secure. You can protect against this (somewhat) by storing the IP Address and the User Agent String that created the session in the session and comparing these against the requesting IP Address and User Agent string for each page access. Just remember that these rely on HTTP headers and can be spoofed.
Cookie 只是存储在客户端中的标识符。这些将通过每个 HTTP 请求提供给服务器。然后,服务器将 cookie 标识符与存储的数据进行匹配,并检索 $_SESSION 的正确值。
The cookies are just identifiers store in the client. These are given to the server with each HTTP request. The server then matches the cookie identifier with stored data and retrieves the correct values for $_SESSION.