简体   繁体   English

会话Cookie与持久Cookie

[英]Session Cookie vs Persistent Cookie

I understand the normal application of a persistent cookie vs a session cookie. 我了解持久性Cookie与会话Cookie的正常应用。 But if you can specify the expiration time of a session cookie to behave like a persistent cookie and vice-versa. 但是,如果您可以指定会话cookie的过期时间使其表现为持久性cookie,反之亦然。 Is there any benefit to using session cookies besides them being obfuscated from the user and the session is stored on the server? 除了将会话cookie从用户中混淆并且将会话存储在服务器上之外,使用会话cookie有什么好处?

session_set_cookie_params() function allows you to set a specific expiration time for a session. session_set_cookie_params()函数允许您设置会话的特定到期时间。 You can set the time in a persistent cookie in the setcookie() function. 您可以在setcookie()函数的永久cookie中设置时间。

I already pulled up the threads Cookie VS Session and Session cookies and persistent cookies , and didn't find my answer. 我已经退出了Cookie VS SessionSession cookie和持久性cookie的线程,却找不到我的答案。

But if you can specify the expiration time of a session cookie to behave like a persistent cookie and vice-versa. 但是,如果您可以指定会话cookie的过期时间使其表现为持久性cookie,反之亦然。

Not true, the difference between a session cookie and a persistent cookie is whether or not the an expires value is given. 并非如此,会话cookie和持久性cookie之间的区别是是否给出了expires值。 A session cookie can't have an expiration time by definition. 根据定义,会话cookie不能具有到期时间。

Is there any benefit to using session cookies besides them being obfuscated from the user and the session is stored on the server? 除了将会话cookie从用户中混淆并且将会话存储在服务器上之外,使用会话cookie有什么好处?

A session ID for something like PHP sessions can be stored in either a session cookie or a persistent cookie, and session cookies can contain other information besides session IDs. 诸如PHP会话之类的会话ID可以存储在会话cookie或持久性cookie中,并且会话cookie可以包含除会话ID之外的其他信息。 They both use the word "session" but are separate things. 它们都使用“会话”一词,但它们是分开的东西。

A session cookie is the right choice if you want the cookie to disappear when the user closes their browser. 如果您希望当用户关闭浏览器时cookie消失,则会话cookie是正确的选择。 A good example is online banking - the cookie that authenticates you should be destroyed when you close the browser so someone can't sneak onto your computer, reopen the browser, and start making transfers. 一个很好的例子是网上银行-当您关闭浏览器时,用于验证您身份的cookie应该被破坏,以使他人无法潜入您的计算机,重新打开浏览器并开始进行转账。 Ever had your facebook status or something like that changed as a prank? 有没有因为恶作剧而改变过您的facebook状态?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM