当前位置:网站首页>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?
边栏推荐
- Fastjson反序列化
- 嵌入式软件组件经典架构与存储器分类
- "Global Digital Economy Conference" landed in N World, Rongyun provides communication cloud service support
- LeetCode 899 有序队列[字典序] HERODING的LeetCode之路
- 像用户体验设计师一样思考
- 面试官:工作两年了,这么简单的算法题你都不会?
- 【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
- What is a smart contract?
- For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
- This article takes you to understand the principle of CDN technology
猜你喜欢
随机推荐
Cookie和Session使用
[Explanation of JDBC and inner classes]
在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
机器学习概述
机器比人更需要通证
GBase 8c分布式数据库,数据如何分布最优?
鸿蒙第三次
MapReduce中ETL数据清洗案例
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
OS层面包重组失败过高,数据库层面gc lost 频繁
JS快速高效开发技巧指南(持续更新)
在 Chrome 开发者工具里通过 network 选项模拟网站的离线访问模式
Dry goods!A highly structured and sparse linear transformation called Deformable Butterfly (DeBut)
谷歌实用插件分享
Basic using MySQL database
Depth study of 100 cases - convolution neural network (CNN) to realize the clothing image classification
增加WebView对localStorage的支持
oracle计算同、环比
像用户体验设计师一样思考
MySQL database combat (1)