Cookie method encapsulation and cookie disadvantage analysis

Source: Internet
Author: User
Tags set cookie microsoft patch

1 varCookieutil = {2Getfunction(name) {3   varCookieName = encodeURIComponent (name) + "=",4Cookiestart =document.cookie.indexOf (cookiename),5Cookievalue =NULL;6   if(Cookiestart >-1) {7    varCookieend = Document.cookie.indexOf (";", Cookiestart);8    if(Cookieend = =-1) {9Cookieend =document.cookie.length;Ten    } OneCookievalue = decodeURIComponent (document.getCookie.substring (Cookiestart +cookiename.length, Cookieend)); A   } -   returnCookievalue; -  }, theSetfunction(name, value, expires, path, domain, secure) { -   varCookietext = encodeURIComponent (name) + "=" + - encodeURIComponent (value); -   if(ExpiresinstanceofDate) { +Cookietext + = "; Expires= "+expires.togmtstring (); -   } +   if(path) { ACookietext + = "; Path= "+path; at   } -   if(domain) { -Cookietext + = "; Domain= "+domain; -   } -   if(secure) { -Cookietext + = "; Secure; in   } -Document.cookie =Cookietext; to  }, +unsetfunction(name, path, domain, secure) { -    This. Set (Name, "",NewDate (0), path, domain, secure); the  } *};
Cookies have a high degree of extensibility and usability, but there are drawbacks: first: The total number of cookies per domain is limited, but there are differences between browsers. As shown below
    • IE6 and lower versions limit up to 20 cookies per domain name.
    • IE7 and later versions each domain name has a maximum of 50. IE7 initially supported a maximum of 20 cookies per domain name and was later updated by a Microsoft patch.
    • Firefox limits a maximum of 50 cookies per domain.
    • Opera restricts a maximum of 30 cookies per domain.

When a cookie is set beyond the limit of a single domain name, the browser clears the previously set cookie. IE and Opera will delete the least recently used (Lru,least recently used) cookie to make room for the new set of cookies. Firefox seems to randomly decide which cookie to erase, so it's important to consider cookie restrictions to avoid unintended consequences.

Second: consider security issues. If a cookie is intercepted, the interceptor can get all the session information. Even if encryption is not used, the interceptor does not need to know the meaning of the cookie, which can cause security problems.

Cookie method encapsulation and cookie disadvantage analysis

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.