Tell me the difference between a cookie and a session.

Source: Internet
Author: User
Tags session id

1.Cookie

In layman's words, some web site-related information is stored locally after visiting certain websites, and some steps are reduced on the next visit. More accurately, cookies are small pieces of text that the server stores on the local machine and are sent to the same server with each request, which is the scenario of keeping the state on the client.
The main contents of a cookie include: name, value, expiration time, path, and domain. Use fiddler grab Bag can see, for example we open a Baidu site can see headers including cookies, as follows:

bidupsid:9d2194f1cb8d1e56272947f6b0e5d47e
pstm:1472480791
BAIDUID:3C64D3C3F1753134D13C33AFD2B38367:FG
Ispeed_lsm:2
Mcity: -131:
pgv_pvi:3797581824
pgv_si:s9468756992
Bduss: Jhnxvoqmhpytvenediunq5s05xchzmmvy5qzfrnvh5szzov0xmvdr6rzv-bejzsvfbqufbjcqaaaaaaaaaaaeaaactexsbynrfy2hpbgqaaaaaaaaaaaaaaaa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALLXKVI5CSLYZJ
Bd_home:1
h_ps_pssid:1423_21080_ 17001_21454_21408_21530_21377_21525_21193_21340
bd_upn:123253
sug:3
sugstore:0
origin:0
bdime:0
Key, in the form of value. The expiration time can be set, if not set, then the browser will disappear, stored in memory, or set the time to be stored on the hard disk, after the expiration of automatic removal, for example, the switch to open the browser after the opening of the explorer he will still exist, the former called the session cookie is also called transient Cookies, which are called persistent cookies, are also called permenent cookies. The path and domain is the corresponding domain name, the cookie of a website can not be used for B naturally.
2.Session

A class hashtable structure in which the server exists to hold user data.
The first time the browser sends a request, the server automatically generates a Hashtable and a session ID to uniquely identify the hashtable and send it to the browser via a response. The second request of the browser will send the session ID in the previous server response to the server, and the server extracts the session ID from the request and compares it with all the session IDs saved, to find the corresponding hashtable of the user.
Generally this value will have a time limit, after timeout, destroy this value, default 30 minutes.
When a user jumps between the Web pages of an application, the variables stored in the session object are not lost but persist throughout the user's session.
The implementation of the session and the cookie has a certain relationship. Create a connection to generate a session ID, open a few pages on several, here is the use of cookies, the session ID exists in a cookie, each time the session ID with the past can be identified.
---------------------
lyf687
Source: CSDN
Original: 80077928?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!

Tell me the difference between a cookie and a session?

1, cookies and sessions are session technology, the cookie is run on the client, the session is run on the server side.

2, the cookie has the size limit and the browser in the number of stored cookies also has the limit, the session is no size limit and the server's memory size is related.    3, the cookie has security hidden danger, can attack by intercepting or local file to find your cookie. 4, session is saved on the server side will exist for some time to disappear, if the session too much will increase the pressure on the server.

Tell me the difference between a cookie and a session.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.