当前位置:网站首页>Cookie and Session usage
Cookie and Session usage
2022-08-03 11:10:00 【51CTO】
One.Why are cookies needed?
A and B both have their own Jingdong accounts, and they have successfully logged in locally (7 days password-free login). At this time, A will send his shopping cart to level up.For B, B cannot view the contents of A's shopping cart by accessing the link with a browser. B may directly enter his own shopping cart or prompt B to log in again and jump to the login page.This scenario shows that the server knows who the client is accessing.But we all know that http is stateless, we need to use cookies to mark who the client is and send it to the server.
II.Cookies and Sessions
A cookie is a set of key-value pairs stored locally.How Cookie works: it is a set of key-value pairs generated by the server and sent to the client and saved locally on the client when the client accesses the server.definition).When the browser visits again, the browser will automatically bring the cookie, so that the server can determine who the server is based on the content of the cookie.
Although the cookie solves the requirement of "maintaining state" to a certain extent and makes up for the stateless defect of the http protocol, the cookie itself only supports a maximum of 4096 bytes; and the cookie itselfIt is stored locally on the client and can be intercepted or intercepted, but there is no guarantee of security.Therefore, at this time, it is necessary to use the session to help solve the problem of maximum bytes and the security problem of saving locally. The session saves the user information on the server.
So, if the session is kept to the server, how does the client bridge the session of the server through the cookie?
This raises the question of how cookies and sessions help?We can assign a unique id to each client's cookie, so that when the user accesses, through the cookie, the server knows who is coming.Then we save the user's private information on the server for a period of time according to the id of different cookies.
In summary: cookie makes up for the lack of stateless http, letting the server know who is coming; but the cookie is stored locally in the form of text, which is more secure.Poor; so we use cookies to identify different users, and correspondingly save the user's private information in the session and the text that can exceed 4096 bytes.
Three.Single use of cookies?
Four.The combined application of Cookie and Session?
边栏推荐
- 面试一面
- 卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
- Traceback (most recent call last): File
- ERC20通证标准是什么?
- 出色的移动端用户验证
- Machine Learning (Chapter 1) - Feature Engineering
- Depth study of 100 cases - convolution neural network (CNN) to realize the clothing image classification
- STM32入门开发 介绍SPI总线、读写W25Q64(FLASH)(硬件+模拟时序)
- build --repot
- 【Star项目】小帽飞机大战(九)
猜你喜欢
随机推荐
numpy
浅谈SVN备份
通过组策略安装软件和删除用户配置文件
MATLAB程序设计与应用 2.6 字符串
【AppCube】数字孪生万物可视 | 联接现实世界与数字空间
「全球数字经济大会」登陆 N 世界,融云提供通信云服务支持
使用.NET简单实现一个Redis的高性能克隆版(一)
【TypeScript】为什么要选择 TypeScript?
鸿蒙第三次
请问应该用什么关键字将内容主题设置为 dark 呢
深度学习100例——卷积神经网络(CNN)实现服装图像分类
【冒泡排序以及奇数偶数排列】
CADEditorX ActiveX 14.1.X
试题G:单词分析 ← 第十一届蓝桥杯大赛第二场省赛赛题
OS层面包重组失败过高,数据库层面gc lost 频繁
CADEditorX ActiveX 14.1.X
微信多开批处理(自动获取安装路径)
在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
【JDBC以及内部类的讲解】
鸿蒙第四次








