📜  Session 和 Cookie 的区别

📅  最后修改于: 2022-05-13 01:57:03.413000             🧑  作者: Mango

Session 和 Cookie 的区别

1. 会议:
会话用于暂时在服务器上保存信息,以便可以在网站的各个页面上使用它。它是花在一项活动上的总时间。用户会话在用户登录到特定的网络应用程序时开始,并在用户退出程序或关闭机器时结束。

会话值更加安全,因为它们以二进制或加密形式保存,并且只能在服务器上解码。当用户关闭机器或退出程序时,会话值会被自动删除。我们必须将值保存在数据库中以永久保存它们。

2. 饼干:
cookie 是保存在用户计算机上的小型文本文件。 cookie 的最大文件大小为 4KB。它也称为 HTTP cookie、Web cookie 或 Internet cookie。当用户第一次访问网站时,网站会以 cookie 的形式向用户的计算机发送数据包。

存储在 cookie 中的信息不安全,因为它以任何人都可以看到的文本格式保存在客户端。我们可以根据需要激活或禁用 cookie。

会话和 Cookie 之间的区别:

Cookie

Session

Cookies are client-side files on a local computer that hold user information.Sessions are server-side files that contain user data.
Cookies end on the lifetime set by the user.When the user quits the browser or logs out of the programmed, the session is over.
It can only store a certain amount of info.It can hold an indefinite quantity of data.
The browser’s cookies have a maximum capacity of 4 KB.We can keep as much data as we like within a session, however there is a maximum memory restriction of 128 MB that a script may consume at one time.
Because cookies are kept on the local computer, we don’t need to run a function to start them.To begin the session, we must use the session start() method.