当前位置:网站首页>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?
边栏推荐
- 深度学习经典网络 -- Inception系列(稀疏结构)
- Machine Learning (Chapter 1) - Feature Engineering
- Analysis of the idea of the complete knapsack problem
- 实现2d人物在跳跃的同时左右移动
- complete knapsack problem
- 怎么在外头使用容器里php命令
- 【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
- 历史拉链数据处理有人做过吗
- redis基础知识总结——数据类型(字符串,列表,集合,哈希,集合)
- ETL data cleaning case in MapReduce
猜你喜欢
随机推荐
深度学习经典网络 -- Inception系列(稀疏结构)
Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
QT with OpenGL(HDR)
MySQL数据库高级使用
LeetCode 899 有序队列[字典序] HERODING的LeetCode之路
Programmers architecture practice way: software architecture basic concepts and thinking
SAP 电商云 Spartacus UI 的 External Routes 设计明细
VRRP协议的作用及VRRP+OSPF配置方法
Cross-chain bridge protocol Nomad suffers hacker attack, losing more than $150 million
numpy
"Global Digital Economy Conference" landed in N World, Rongyun provides communication cloud service support
完全背包问题的思路解析
【多线程的相关内容】
科普大佬说 | 黑客帝国与6G有什么关系?
Traceback (most recent call last): File
浅谈SVN备份
numpy
OS层面包重组失败过高,数据库层面gc lost 频繁
微信小程序获取用户手机号码
Boolean 与numeric 无法互转




![[Bubble sort and odd-even sorting]](/img/89/d63afe1900a05b2a5615fcc3c09ccb.png)



