当前位置:网站首页>The difference between cookies and sessions
The difference between cookies and sessions
2022-07-19 02:41:00 【Do you eat oil cake】
Catalog
cookie
1、 What is? cookie
Cookie Meaning for “ cookie ”, By W3C organisation , The earliest by Netscape A mechanism for community development . at present Cookie Has become the norm , All the major browsers such as IE、Netscape、Firefox、Opera Such as support Cookie.
2. Why use cookie
because http Is stateless protocol ( The server and client do not know each other )
About http The details of the agreement can be moved http agreement
Cookies Are small files stored on the user's computer . It is designed to store user data for some sites , This allows the server to customize content for such users . Page code can get Cookie The value is then sent to the server , such as Cookie The location is stored in , In the future, each time you enter the map, you can locate the changed location by default .
3、cookie How it works
- When the user logs in for the first time , Send request to server
- Server according to user information , The server helps users create a cookie To identify the user , Stored in a database , And send it to the browser
- The browser will get cookie The data is stored in the local browser .(cookie Saved by the client )
- When sending the request again , The server will retrieve cookie, Verify user identity
- cookie The simple workflow diagram of is convenient for everyone to understand :

4、cookie Characteristics :
Save to client , Easy to tamper with ( Delete 、 Ban )
The amount of data saved is limited ( Limited size , Maximum 4kb)
Easy to understand and use
session
1、 What is? session
Session It's another mechanism for recording customer status , The difference is Cookie Save in the client browser , and Session Save on the server . When the client browser accesses the server , The server records client information in some form on the server . This is it. Session. The client browser only needs to access it from that Session To find the status of the customer session It's a special kind cookie.cookie It's saved on the client side , and session It's stored in the server .
2. Why use session
because cookie There is a client , And its own storage size is limited , The key is that users can be visible , And can be modified at will , Very unsafe . Then how to be safe again , It is also convenient to read information globally ? therefore , This is the time , A new storage session mechanism :session The birth of !
3、session How it works
- The client requests the server for the first time ;
- The server generates a session Save the data on the server (session) Of id With cookie Passed to the client in the form of ;
- The client requests the server for the second time , The browser will automatically carry cookie To access the server (session_id);
So visible ,session most important of all session_id, Stored in cookie in , therefore session Depend on cookie, When a browser is disabled cookie function ,session It can't be used !
- Let's take a brief look at session Work flow chart :

4、session Characteristics
- Used to store multiple requests for a session , There is a server .
- Can store any type , Data of any size
- Depend on cookie, Browser disable cookie,session It can't be used
- sessionId Store in cookie in , At this time, if some browsers do not support cookie, At this point, you need to rewrite the code , take sessionID Put it in url in , It's not safe
cookie and session The difference between
1、 Save in different locations
cookie Store on client , and session Store on the server
2、 It's used in different ways
cookie: If on the browser side cookie Set the corresponding time , be cookie Save in local hard disk , If it doesn't expire at this time , Then you can use , If it expires, delete . If No, right cookie Setup time , The browser is closed by default ,cookie It will be deleted .
session: We're on request , If there is... In the request sent session_id, Then you will find the corresponding session object , If it doesn't exist session_id, On the server side, a session object , And will sessionId Return to the client , You can put it in cookie in , transmitted .
3、 Storage content is different
cookie Only strings can be stored , and session The storage structure is similar to hashtable structure , Can store any type of .
4、 Different storage sizes
cookie Can be stored at most 4k Size content ,session There is no limit .
5、 Different security
session The security of is higher than cooKie
6、 Different performance
session It will occupy more server performance , When accessing more applications cookie
边栏推荐
- [tools] unity quickly starts to make the artifact tilemap of 2D and 2.5D games
- Leetcode buckle classic topic - 82 Maximum rectangle in column chart
- Metersphere is based on JMeter distributed performance pressure testing platform
- BeanShell script gets the current time
- How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)
- ARM 交叉编译器命名规则
- status 500 reading AftersaleService#getAftersaleList(Long)+com. sun. proxy.$ Proxy214.getAftersaleList
- shell脚本接收和返回参数
- 理解 继承、多态、抽象以及它们的概念
- Detailed explanation of caduceus project of metauniverse public chain (I): project concept and technical framework of caduceus metaverse protocol
猜你喜欢

Detailed explanation of caduceus project of metauniverse public chain (I): project concept and technical framework of caduceus metaverse protocol

How to use nmon

Getting to know Alibaba cloud environment construction for the first time: unable to connect remotely, and having been in the pit: the server Ping fails, FTP is built, the server builds the database,

Leetcode buckle classic question - 42 Connect rainwater

JS note 1
![[unity development tips] unity mixer mixer controls global volume](/img/dd/12b307d5e69609c1471bad8174c20e.png)
[unity development tips] unity mixer mixer controls global volume

VLAN和TRUNK口配置

Zabbix6.0通过iDRAC,IMM2监控DELL,IBM服务器硬件

Leetcode buckle classic topic - 82 Maximum rectangle in column chart

逆元(名字太多人用我就加这几个字)
随机推荐
Shortest circuit / secondary short circuit /k short circuit
Attack and defense the world ---- shrink
[Ruiji takeout ⑩] rough learning of Linux & rough learning of redis
next数组-循环节
Shell脚本case分支语句、扒匿名登录FTP的max地址
innodb、Mysql结构、三种删除的区别
In depth performance test data analysis
WINRAR命令拷贝指定文件夹为压缩文件,调用计划任务进行备份。
Leetcode --- one question per day
【已解决】参考了本地mysql忘记密码后, [Server] --initialize specified but the data directory has files in it. Aborti
postman的json脚本转jmeter的jmx脚本
使用Grafana8.5.2显示zabbix6.0的信息
ARM 交叉编译器命名规则
全链路压测
Flask template injection
Performance traffic playback
Uniapp wechat applet login (authorize wechat first and then mobile phone number) - (1)
网络层协议和IP数据包的格式(详解)
树状数组与ST表
理解:什么是接口,接口的概念