Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is cookie?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is cookie". In daily operation, I believe many people have doubts about what is cookie. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is cookie?" Next, please follow the editor to study!

1. What is cookie?

Cookie is the browser cache

What is caching? Buffer for data exchange > temporary storage.

Cookie features. Cookie takes effect under the same domain name. Cookie storage is limited. 4: 10k, can not store 50, there is expiration time.

> caching

2.cookie usage

[xss_clean] =''

Format requirements for cookie. Name = value

Session cookie

Review the Date object

What do the parameters in setDate () do after the date time is exceeded?

SetDate (getDate () + 8000)

Expires=

'user=yanghuaizhi;expires='+d

Encapsulated cookie

Function setCookie (name,value,expirs) {

Var d=new Date ()

D.setDate (d.getDate () + expirs)

[xss_clean] = name+'='+value+';expires='+expirs

}

Get cookie

Function getCookie (name) {

Var arr=doucment.cookie.split (';')

For (var I = 0; I < arr.length; I + +) {

Var arr2= arr [I] .split ('=')

If (arr2 [0] = = name) {

Return arr2 [1]

}

}

Return''

}

Debugging of cookie:

3. Delete cookie

Function removeCookie (name) {

SetCookie (name,1,-1); / / 1 is an arbitrary value, which can be any value;-1 is the expiration time

}

Encapsulation of cookie

Var cookie= {

SetCookie:function (name,value,date) {

Var d=new Date ()

D.setTime (d.getTime () + date)

[xss_clean] = name+'='+value+';expires='+d

}

GetCookie:function (name) {

Var arr= [XSS _ clean] .split (';')

For (var I = 0; I < arr.length; I + +) {

Var arr2= arr [I] .split ('=')

If (arr2 [0] = = name) {

Return arr2 [1]

}

}

Return''

}

RemoveCookie:function (name) {

Cookie.setCookie (name,'',-1)

}

}

At this point, the study of "what is cookie" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report