当前位置:网站首页>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?
边栏推荐
- 科普大佬说 | 黑客帝国与6G有什么关系?
- GBase 8c与openGauss是什么关系?
- 使用.NET简单实现一个Redis的高性能克隆版(一)
- 记某社区问答
- 在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
- C#/VB.NET 从PDF中提取表格
- complete knapsack problem
- 完全背包问题的思路解析
- MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded
- 【无标题】函数,对象,方法的区别
猜你喜欢

Classical Architecture and Memory Classification of Embedded Software Components

complete knapsack problem

机器学习(第一章)—— 特征工程

如何通过DBeaver 连接 TDengine?

The way of programmer architecture practice: how to design a sustainable evolution system architecture?

Web Server 设置缓存响应字段的一些推荐方案

卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
![LeetCode 899 有序队列[字典序] HERODING的LeetCode之路](/img/95/1b63cfb25b9e0802666114f089fcb8.png)
LeetCode 899 有序队列[字典序] HERODING的LeetCode之路

Matplotlib

全新的Uber App设计
随机推荐
C - 为什么指针常常初始化为 NULL?
用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
MATLAB programming and application 2.7 Structural data and unit data
[华为云在线课程][SQL语法入门][学习笔记]
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
MySQL database combat (1)
ScrollView嵌套RecyclerView滚动冲突
MySQL数据库实战(1)
complete knapsack problem
Question G: Word Analysis ← Questions for the second provincial competition of the 11th Blue Bridge Cup Competition
关于OPENSSL的问题
程序员架构修炼之道:软件架构基本概念和思维
优炫数据库在linux平台下服务启动失败的原因
【TypeScript】Why choose TypeScript?
请问应该用什么关键字将内容主题设置为 dark 呢
Web Server 设置缓存响应字段的一些推荐方案
混动产品谁更吃香,看技术还是看市场?
Dva.js 新手入门指南
507. 完美数
Depth study of 100 cases - convolution neural network (CNN) to realize the clothing image classification