Home  >  Article  >  Backend Development  >  What is the difference between cookies and sessions?

What is the difference between cookies and sessions?

清浅
清浅Original
2018-11-30 13:59:3777036browse

The difference between cookie and session is: cookie is stored in text format on the browser, and the storage capacity is limited; while session is stored on the server, it can store multiple variables unlimitedly and is more secure than cookie

In php, you can specify that the visitor information of the site is stored in the session or cookie. They can both accomplish the same thing. So what are their differences? I will introduce it in detail in the article.

[Recommended courses: PHP course, JavaScript course]

What is the difference between cookies and sessions?

cookie

is located on the user's computer and is used to maintain the information in the user's computer until the user deletes it. For example, if we enter the user name and password when logging into a certain software on a web page and save it as a cookie, we will not need to log in to the website every time we visit. We can save any text on the browser, and we can block or delete it anytime and anywhere. We can also disable or edit cookies, but one thing we need to be careful about is not to use cookies to store some private data to prevent privacy leaks

What is the difference between cookies and sessions?

session

session is called session information and is located on the web server. It is mainly responsible for the interaction between the visitor and the website. When the access browser requests the http address, it will be passed to the web server and matched with the access information. When When you close the website, it means that the session has ended. The website cannot access the information, so it cannot save permanent data. We cannot access and disable the website

What is the difference between cookies and sessions?

session and cookies The difference

(1) Cookie is stored in the browser in text file format, while session is stored on the server side, which stores a limited amount of data. It only allows 4kb it doesn't save multiple variables in the cookie.

(2) Cookie storage limits the amount of data, only 4KB is allowed, while session is unlimited

(3) We can easily access the cookie value but we cannot easily access the session value. Therefore it is safer

(4) Setting the cookie time can make the cookie expire. But using session-destroy(), we will destroy the session.

Summary: If we need to log in to a site frequently, it is best to use cookies to save information, otherwise it will be particularly troublesome to log in every time. If we need to use it for sites that require high security and the ability to control data Session effect is better, of course we can also combine the two to make the website run according to our ideas

The above is the detailed content of What is the difference between cookies and sessions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more