The difference between functional cookies, sessionstorage, and Localstorage in PHP

Source: Internet
Author: User
Tags setcookie sessionstorage
Cookies: Data (usually encrypted) stored on the user's local terminal (client Side) by certain websites in order to identify users.

The concept of Web Storage (Localstorage and Sessionstorage) is similar to a cookie, except that it is designed for larger capacity storage. The size of the cookie is limited, and every time you request a new page, the cookie is sent past, which virtually wastes bandwidth, and the cookie needs to specify the scope and cannot be called across domains.

In addition, WEB storage has methods such as setitem,getitem,removeitem,clear, unlike cookies that require front-end developers to encapsulate Setcookie,getcookie themselves.

However, cookies are also not available or missing: The role of cookies is to interact with the server as part of the HTTP specification, and the Web storage only for local "storage" of data

(1) Limitation:
Cookies are generated by the server and can be set to expire, and if the browser generates cookies, the cookies are disabled by default when the browser is closed;
Sessionstorage is only saved in the current session, the page or browser will be erased when it is closed;
Localstorage is permanently present unless it is cleared;
(2) Capacity:
Cookies have a small capacity of about 4k,
Sessionstorage and localstorage capacity of about 4M;

The difference between Sessionstorage and localstorage

Sessionstorage is used to store data locally in a session, which can only be accessed by a page in the same session and destroyed when the session ends. So sessionstorage is not a persistent local store, only session-level storage. When the user closes the browser window, the data is immediately deleted.

Localstorage is used for persistent local storage, and the data is never expired unless the data is actively deleted. It is also the use of Key-value to store data, the underlying data interface is SQLite, according to the domain name of the data are saved to the corresponding database file. It can save larger data (IE8 on the 10mb,chrome is 5MB), while the saved data is no longer sent to the server, to avoid bandwidth waste.

The difference between a cookie and a session:

1) The cookie data is stored on the client's browser and the session data is placed on the server.

2) Cookies are not very secure and others can analyze cookies stored locally and make cookie spoofing, taking into account that security should use the session.

3) session will be saved on the server for a certain period of time. When the increase in access, will be compared to the performance of your server to reduce the performance of the server, you should use cookies.

4) A single cookie cannot hold more than 4K of data, and many browsers limit a maximum of 20 cookies per site.

5) So the proposal: the login information and other important information stored as a session; Additional information can be placed in a cookie if it needs to be retained

Cookies: Data (usually encrypted) stored on the user's local terminal (client Side) by certain websites in order to identify users.

The concept of Web Storage (Localstorage and Sessionstorage) is similar to a cookie, except that it is designed for larger capacity storage. The size of the cookie is limited, and every time you request a new page, the cookie is sent past, which virtually wastes bandwidth, and the cookie needs to specify the scope and cannot be called across domains.

In addition, WEB storage has methods such as setitem,getitem,removeitem,clear, unlike cookies that require front-end developers to encapsulate Setcookie,getcookie themselves.

However, cookies are also not available or missing: The role of cookies is to interact with the server as part of the HTTP specification, and the Web storage only for local "storage" of data

(1) Limitation:
Cookies are generated by the server and can be set to expire, and if the browser generates cookies, the cookies are disabled by default when the browser is closed;
Sessionstorage is only saved in the current session, the page or browser will be erased when it is closed;
Localstorage is permanently present unless it is cleared;
(2) Capacity:
Cookies have a small capacity of about 4k,
Sessionstorage and localstorage capacity of about 4M;

The difference between Sessionstorage and localstorage

Sessionstorage is used to store data locally in a session, which can only be accessed by a page in the same session and destroyed when the session ends. So sessionstorage is not a persistent local store, only session-level storage. When the user closes the browser window, the data is immediately deleted.

Localstorage is used for persistent local storage, and the data is never expired unless the data is actively deleted. It is also the use of Key-value to store data, the underlying data interface is SQLite, according to the domain name of the data are saved to the corresponding database file. It can save larger data (IE8 on the 10mb,chrome is 5MB), while the saved data is no longer sent to the server, to avoid bandwidth waste.

The difference between a cookie and a session:

1) The cookie data is stored on the client's browser and the session data is placed on the server.

2) Cookies are not very secure and others can analyze cookies stored locally and make cookie spoofing, taking into account that security should use the session.

3) session will be saved on the server for a certain period of time. When the increase in access, will be compared to the performance of your server to reduce the performance of the server, you should use cookies.

4) A single cookie cannot hold more than 4K of data, and many browsers limit a maximum of 20 cookies per site.

5) So the proposal: the login information and other important information stored as a session; Additional information can be placed in a cookie if it needs to be retained

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.