当前位置:网站首页>会话和饼干,令牌
会话和饼干,令牌
2022-07-31 06:24:00 【Forevermoremo】
Session
Session is a technology that records user information on the server side. Generally, Session is used to share data between the server side and the client side.
Cookies
Cookie is a technology that records user information on the client side. Because the http protocol is stateless, cookies are generated to solve this problem.
Cookies are stored in the browser's built-in Cookies.As shown:

Cookie is a piece of small text data not exceeding 4KB, consisting of a name (Name), a value (Value) and several other optional attributes used to control the validity period, security, and scope of use of the cookie.
The client requests the server, and if the server needs to record the user status, it uses the response to issue a cookie to the client browser.The client browser will save the cookie.When the browser requests the website again, the browser submits the requested address to the server together with the cookie.The server checks the cookie to identify the user's status.The server can also modify the content of the cookie as needed.
Session and Cookies
Session generally relies on cookies. Sessions are created to pass the sessionId through cookies, and then passed to the server when the client requests.Therefore, it is necessary to confirm whether the browser has enabled cookie storage.
Server-based authentication is as follows:
1. The user sends a request with a username and password.
2. Program verification, if the client request does not contain sessionId, the server creates a session for this client and generates a sessionId associated with this session, and returns the SESSIONID to the client.
4. The client stores the SessionId in Cookies, and each time a request is made, the browser will automatically carry the Cookie to the server.
5. Server-side retrieval.If the retrieval is successful, the requested data will be returned, and if the retrieval fails, an error code will be returned.
As shown:

Token
Token-based authentication is stateless, we do not need to store user information in the server or session.
The process of Token-based authentication is as follows:
1. The user sends a request with a username and password.
2. Program verification, after the verification is successful, the Token will be returned to the client.
4. The client stores the Token, and each access to the API carries the Token to the server.
5. The server side uses the filter filter to verify.If the verification is successful, the request data will be returned, and if the verification fails, an error code will be returned.
Each request token should be sent in the HTTP header to ensure that the HTTP request is stateless.We can allow the server to accept requests from all domains by setting the server property Access-ControlAllow-Origin:* .
The process is shown in the figure:

Summary
Session, Cookie, and Token are both used for data sharing between the server and the client.
Session is a server-based authentication. With the rise of Web mobile terminals, some memory overhead, scalability, and cross-domain problems are gradually exposed. Token can just solve these problems, although the server involves more,But it also facilitates our front-end to solve cross-domain problems.
Reference:
https://www.cnblogs.com/moyand/p/9047978.html
https://blog.csdn.net/deft_mkjing/details/53762277
边栏推荐
猜你喜欢

活体检测PatchNet学习笔记

DSPE-PEG-Biotin,CAS:385437-57-0,磷脂-聚乙二醇-生物素可延长循环半衰期

random.randint函数用法

Flutter mixed development module dependencies

mPEG-DMPE Methoxy-polyethylene glycol-bismyristyl phosphatidylethanolamine for stealth liposome formation

CNN的一点理解

Numpy常用函数

Understanding of objects and functions in js

Sourcery插件(自动提升代码质量)

DSPE-PEG-Azide DSPE-PED-N3 磷脂-聚乙二醇-叠氮脂质PFG
随机推荐
活体检测PatchNet学习笔记
活体检测FaceBagNet阅读笔记
应用usb_cam同时打开多个摄像头方法
ERROR Error: No module factory availabl at Object.PROJECT_CONFIG_JSON_NOT_VALID_OR_NOT_EXIST ‘Error
Gradle sync failed: Uninitialized object exists on backward branch 142
MYSQL事务与锁问题处理
朴素贝叶斯文本分类(代码实现)
超参数优化-摘抄
微信小程序源码获取与反编译方式
MW: 3400 4-Arm PEG-DSPE four-arm-polyethylene glycol-phospholipid a saturated 18-carbon phospholipid
日志jar包冲突,及其解决方法
学习JDBC之获取数据库连接的方式
Embedding前沿了解
unicloud cloud development record
Cholesterol-PEG-Azide CLS-PEG-N3 Cholesterol-PEG-Azide MW:3400
function in js
Redis-哈希
JS写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数JS
DSPE-PEG-Biotin,CAS:385437-57-0,磷脂-聚乙二醇-生物素可延长循环半衰期
Pytorch学习笔记13——Basic_RNN