Cookie和会话是否依赖于彼此? [英] Are cookies and sessions are depend on each other?

查看:247
本文介绍了Cookie和会话是否依赖于彼此?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



删除或清除其中一个是否会影响另一个?



通过在浏览器中禁止其中一个影响另一个?是否通过

PS我是新手。



编辑:在撰写问题时我是新手。这个问题是很多新手都面临的。

解决方案

他们完全是独立 ...




  • Cookie不能存储无限制的值,会话可以

  • 如果禁用用户浏览器cookie,则无法将数据存储在cookie中,因为可以在会话中,因为会话ID可以追加到URL

  • 最好将数据存储在会话中,而不是存储在cookies中,因为Cookie可以缓和

  • 如果您删除Cookie ,那么只有您的站点中的那些功能将被禁用,您将在其中检索这些Cookie数据,但您将被登录,如果删除会话cookie,则您将被注销..(1)

  • Cookie存储在您的服务器上存储会话的客户端计算机上

  • 如果您在Cookie停留在您旁边时关闭浏览器,则会话结束,除非用户手动删除或直到他们过期



您可以更好地控制会话,而不是



(1)例如,如果您正在设置cookie名称演示,而您正在使用闪屏,除非直到演示设置,您将显示一个初始屏幕

  if(!isset($ _ COOKIE ['demo']) ){//现在这将显示灯箱总是如果用户已经禁用了他的cookie 
< script> ...< / script>
}

文章



http://www.klovera.com/php-sessions-vs-cookies/



参考



会话



Cookies


Are cookies and sessions depend on each other in PHP?

Does deleting or clearing either one of them affect the other?

Does by disabling either one of them in the browser affect the other?

P.S. I am newbie.

Edit: I was newbie at time of writing question. This question is faced by many newbies.

解决方案

They are totally independent...

  • Cookies cannot store unlimited value, sessions can
  • You cannot store data in a cookie if user browser cookie is disabled where in session you can, because session id can append to URL
  • It is better to store data in sessions than to store in cookies because cookies can be tempered
  • If you delete cookies, then only those functionalities in your site will be disabled in which you are retrieving these cookies data but you'll be logged in and if you delete session cookie, you'll be logged out.. (1)
  • Cookies are stored on client machine where session are stored on your server
  • A session is ended if you close you browser while cookies stay there unless they are manually removed by the user or till they are expired

Inshort you've better control over sessions than on cookies

(1) For example if you are setting a cookie name demo and you are using a splash screen unless and until the demo is set you'll show a splash screen

if(!isset($_COOKIE['demo'])) { //Now this will show lightbox always if user has disabled his cookies
   <script>...</script>
}

Articles

http://www.klovera.com/php-sessions-vs-cookies/

Reference

Session

Cookies

这篇关于Cookie和会话是否依赖于彼此?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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