当前位置:网站首页>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?
边栏推荐
- 通过组策略安装软件和删除用户配置文件
- redis基础知识总结——数据类型(字符串,列表,集合,哈希,集合)
- [华为云在线课程][SQL语法入门][学习笔记]
- 白帽黑客与留守儿童破壁对“画”!ISC、中国光华科技基金会、光明网携手启动数字安全元宇宙公益展
- 【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
- build --repot
- Web Server 设置缓存响应字段的一些推荐方案
- 机器学习(第一章)—— 特征工程
- MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded
- [Output each bit of an integer, from high to low.With and without recursion]
猜你喜欢

全新的Uber App设计

Programmers architecture practice way: software architecture basic concepts and thinking

使用.NET简单实现一个Redis的高性能克隆版(一)

成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...

Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)

Basic using MySQL database

科普大佬说 | 黑客帝国与6G有什么关系?

数据库一席谈:打造开源的数据生态,支撑产业数字化浪潮

MapReduce中ETL数据清洗案例

如何检索IDC研究报告?
随机推荐
VRRP协议的作用及VRRP+OSPF配置方法
完全背包问题
XDR平台架构与关键技术解析
Question G: Word Analysis ← Questions for the second provincial competition of the 11th Blue Bridge Cup Competition
MapReduce中ETL数据清洗案例
MATLAB程序设计与应用 2.7 结构数据与单元数据
实现2d人物在跳跃的同时左右移动
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
Simple implementation of a high-performance clone of Redis using .NET (1)
Who is more popular for hybrid products, depending on technology or market?
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
RecyclerView的item高度自适应
Activiti产生的背景和作用
509. 斐波那契数
Basic using MySQL database
[Star Project] Little Hat Plane Battle (9)
The way of programmer architecture practice: how to design a sustainable evolution system architecture?
Win10/11 删除文件资源管理器左侧栏目文件夹
通过组策略安装软件和删除用户配置文件
QT with OpenGL(HDR)