Hello, everyone. I am Zhang Xuefei, an honest, pure and kind-hearted Web programmer, a student of the 22nd session of Beijing General Institute of IT Xiuzhen

So today I’m going to talk about deep thinking —— —— domain name, what is COOKIE? What’s the use? What’s the difference between a COOKIE and a SESSION? What is the validity period of the COOKIE?

1. Background

An IP address is a number used to identify Internet hosts as routing addresses, which is not easy to remember.

Thus, the domain name is a character identification. Cookie is called “small text file” in Chinese,

Data stored (usually encrypted) on a user’s Client Side by some web sites to identify the user.

Defined in RFC2109. It was invented in March 1993 by Lou Monterey, a former Netscape employee.

2. Knowledge analysis

Domain names are used on the Internet instead of IP addresses because IP addresses have no real meaning and are not easy for people to remember,

So use meaningful English letters instead. On the web, you have DNS.

To convert a domain name to an IP, so people type in a domain name, convert it to an IP on DNS,

To find the corresponding server, open the corresponding web page.

The purpose of the cookie

Because the HTTP protocol is stateless, meaning that the server does not know what the user did last time, interactive Web applications are severely hampered. In a typical online shopping scenario, the user browses through several pages and buys a box of cookies and two drinks. At the end of the checkout, due to the stateless nature of HTTP, the server does not know what the user has bought without additional means. So cookies are one of the “extra tricks” you can use to get around HTTP’s statelessness. Cookies can be set or read by the server to maintain state in the session between the user and the server. In the shopping scenario, when the user selects the first item, the server sends the user a web page and a Cookie to record the information about the item. When a user visits another page, the browser sends a Cookie to the server, so the server knows what he purchased. As the user continues to buy a drink, the server appends new product information to the original Cookie. At checkout, the server reads the Cookie sent to it.

3. Frequently Asked Questions

Validity period of COOKIE

The difference between cookies and sessions

4. Solutions

Validity period of COOKIE

Cookies can be roughly divided into two states

Cookies of a temporary nature. The site stores some of your personal information during current use, and this information is deleted from your computer when the browser is closed.

Sets the cookie of expiration time. Even when the browser is closed, the information remains on the computer. Such as login name and password, so that you do not have to log in every time you visit a particular site. These cookies can remain in a computer for days, months or even years.

A session is similar to a cookie and is used to solve the problem of Http not maintaining state. The difference between:

1. Cookie data is stored in the client’s browser, and session data is stored on the server.

2. Cookies are not very secure. Others can analyze cookies stored locally and cheat cookies

Sessions should be used for security reasons.

3. Sessions are stored on the server for a certain period of time. When the number of visits increases, it takes a lot of performance out of your server

Cookies should be used to alleviate server performance.

4. The data saved by a single cookie cannot exceed 4K. Many browsers limit the maximum number of cookies saved by a site to 20.

5. Personal suggestions:

Store important information such as login information as SESSION

Other information can be stored in cookies if needed

5. Coding

By default, cookies are automatically cleared when the browser closes, but we can use Expires to set a cookie’s expiration date. The syntax is as follows:

document.cookie = “name=value; expires=date”

The date value in the preceding code is a date string in GMT format, which is generated as follows:

var _date = new Date();

_date.setDate(_date.getDate()+30);

_date.toGMTString();

The above three lines of code can be broken down into several steps:

New generates an instance of Date to get the current time.

The getDate() method gets the day of the current local month, followed by 30 to keep the cookie locally for 30 days;

The time is then set using the setDate() method;

Finally, the toGMTString() method converts the Date object to a string and returns the result

6. Expand your thinking

What is domain Name Resolution Service (DNS)

7. References

Reference number one: Darren

8. More discussion

Question 1: What are the methods to delete cookies?

Answer: 1, set its value to null;

Write a name with the same name, domain with the same value, path with the same value,

Cookies that have the same/different duration (max-age/expires value is the same/different), but have a null value (value is null);

2. Set the Cookie’s expiration date to a point in time that has passed, such as yesterday or last year.

Write a name (name = same), same domain (name = same), same path (path = same), null/not null (value = null/not null)

Cookie, but the past time/value expires in the next millisecond (max-age/expires is the last minute, last year, yesterday equivalent,

Max-age =1 ms, etc.);

Q2: What is domain name resolution?

Answer: Domain name resolution refers to the domain name pointing to the website space IP, so that people can easily access the website through the registered domain name. Domain name resolution is also called domain name pointing, server setup, domain name configuration, reverse IP registration, and so on. To put it simply, the resolution of a memorable domain name into AN IP address is performed by the DNS server, which resolves the domain name to an IP address, and then binds a subdirectory to the domain name on the host of the IP address.

If it is the need to build a site, in addition to domain name registration, also need to apply for space to the virtual host provider, if the space is also need to back up, foreign space is not needed.

Question 3: If the Cookie is not set to expire, when is the Cookie deleted?

Answer: If you do not set the save time, cookies will last until the browser is closed.

thanks

Thank you for watching

BY: this fix | liu Ming

The title 9:

Thanks to Qin Xiu and Liu Ming for perfecting this tutorial on the basis of her technical sharing!

PPT

Video Address:

Links:

https://pan.baidu.com/s/1cjiSZc

Password: CRTB

———————————————————————————————————————— ——————

Skill tree.IT Monastery

“We believe that everyone can become an engineer. From now on, find a senior to guide you to the entrance, control the pace of your own learning, and no longer feel confused on the way to learning.”

Here is the skill tree.IT Shuzhen Institute, where thousands of brothers find their own learning route, learning transparent, growth visible, brothers 1 to 1 free guidance. Come and study with me!

There’s a surprise here