会话与 cookie
这就是session和cookie的区别。我知道会话是服务器端,由服务器管理,cookie 是客户端,由浏览器管理。
我不知道为什么,但我认为这些东西都是多余的。哪些数据必须保存在会话变量中,哪些数据保存在 cookie 中?
Which is the difference between sessions and cookies. I know that sessions are server side, and managed by the server, and the cookies are client side and managed by the browser.
I don't know why, but I see those things as rendundant. Which data have to be keept in a session variable and which on cookies?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Session是通过cookie来实现的。您通常会在 cookie 中保存诸如用户 ID 之类的内容,或者一些可以让您知道用户是谁的标识符,并使用该信息作为服务器端会话变量的密钥。
最重要的是,您不希望在客户端存储任何秘密信息,因为 cookie 很容易被盗(从安全角度来看)。
不要忘记 HTTP 是无状态的,因此 cookie 只是绕过它的一种方法。
Session is implemented with cookies. You would normally save in a cookie things like the user id, or some identifier that will allow you to know who the user is, and use that information as a key for your session variable on the server side.
Most importantly, you wouldn't want any secret information being stored on the client side, since cookies can easily be stolen (from a security point of view).
Don't forget that HTTP is stateless, so cookies are just a way to bypass this.
简而言之,cookie 比会话更持久。一旦关闭浏览器,会话信息就会消失。因此,会话无法存储有关网站/用户对的信息。 Cookie 可以,并且用于允许您保持网站登录状态或存储该网站的首选项(例如语言)等。
In short, cookies are more persistent than sessions. As soon as you close your browser, the session information is gone. Therefore a session has no way to store information about a website/user pair. Cookies do, and are used for things like allowing you to stay logged in to a website, or storing preferences for that website (e.g. language).
Cookie 和会话之间的主要区别在于,Cookie 存储在用户的浏览器中,而会话则不然。这种差异决定了每种产品的最佳用途。
参见
http://php.about.com/od/learnphp/qt /session_cookie.htm
The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for.
see
http://php.about.com/od/learnphp/qt/session_cookie.htm
Cookie 用于小数据。他们只能握住绳子。
在会话变量中,您可以将对象存储在服务器内存中。
Cookies are for small data. They can only hold strings.
In session variables you're able to store objects in the server memory.