Home  >  Article  >  Backend Development  >  What are the differences between php cookies and sessions?

What are the differences between php cookies and sessions?

藏色散人
藏色散人Original
2020-06-30 10:05:502869browse

The difference between cookie and session is: 1. Cookie is a mechanism that stores data on the remote browser side and uses it to track and identify users, while session is used in PHP to keep users continuously accessing web applications. Relevant data; 2. Cookies are not very safe, but sessions are relatively safe.

What are the differences between php cookies and sessions?

Cookie and Session

Cookie: PHP transparently supports HTTP cookies. Cookie is a mechanism that stores data on the remote browser side and uses it to track and identify users

Session: The session mechanism (Session) is used in PHP to maintain relevant data when users continuously access web applications

The difference between php cookie and session

1. Cookie data is stored on the client's browser, and session data is placed on the server.

2. Cookies are not very safe. Others can analyze the COOKIE stored locally and deceive COOKIE

Considering security, session should be used.

3. The session will be saved on the server within a certain period of time. When access increases, it will take up more of your server's performance

In order to reduce server performance, COOKIE should be used.

4. The data saved by a single cookie cannot exceed 4K. Many browsers limit a site to save up to 20 cookies.

5. So personal suggestion:

Store important information such as login information as SESSION

If other information needs to be retained, it can be placed in COOKIE

For details, please visit "PHP cookie" and "PHP session"

The above is the detailed content of What are the differences between php 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