Comparison of session and cookie in php, phpsessioncookie_PHP tutorial

WBOY
Release: 2016-07-13 10:08:54
Original
1044 people have browsed it

Comparison of session and cookie in php, phpsessioncookie

This article compares the differences between session and cookie in PHP in more detail. Share it with everyone for your reference. The specific analysis is as follows:

1. Storage location

Cookies are saved on the client side, and sessions are saved on the server side in the file system/database/memcache, etc.

2. Security

Because the session is saved on the server side, the security is undoubtedly higher.

3. Network transmission volume

Cookies are transmitted between the client and the server through the network, which will occupy some bandwidth; while the session is saved on the server and does not need to be transmitted.

4. Storage time (life cycle), take 20 minutes as an example

The life cycle of a cookie is cumulative, starting from the time of creation. The life cycle ends after 20 minutes, that is, the cookie is invalid;

The life cycle of session is interval. The time starts from the time of creation. If the session is not accessed within 20 minutes, the session will expire in 20 minutes. If the session is accessed at any time within 20 minutes, the session life cycle will restart.

5. Effective paths of session and cookie

By default, cookies only take effect in the directory of the current file. Generally, you need to set the fourth parameter of setcookie to the root directory, so that the entire website page takes effect; by default, session takes effect in the root directory ( You can know it by looking at the PHPSESSID information of the cookie, or setting it through session.cookie_path in the php.ini file).

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/948404.htmlTechArticleComparison of session and cookie in php, phpsessioncookie This article compares the difference between session and cookie in php in more detail. Share it with everyone for your reference. The specific analysis is as follows: 1. The storage bit...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!