This article compares the session in PHP with the cookie difference in detail. Share to everyone for your reference. The specific analysis is as follows:
1, the location of storage
Cookies are saved on the client, session is saved on the server-side file system/database/memcache, and so on.
2. Safety
Session because Save server side, security is undoubtedly higher.
3, Network Transmission volume
Cookies are transmitted over the network between the client and the server, consuming some bandwidth, while sessions are saved on the server side and do not need to be transmitted.
4, Save time (life cycle), take 20 minutes as an example
The life cycle of a cookie is cumulative, calculated from the time it was created, and the life cycle ends after 20 minutes, that is, the cookie is invalid;
The life cycle of the session is interval. The timer starts at the time of creation, and if the session is not accessed within 20 minutes, it expires at 20 minutes. If the session is accessed at any time within 20 minutes, the session's lifecycle will be recalculated.
5, session and the effective path of the cookie
Cookies by default, cookies only take effect in the current file's directory, and you typically need to set the fourth parameter of Setcookie to the root directory, which will take effect on all pages of the site. The session is under the root directory by default (it can be known by looking at the PHPSESSID information of the cookie, or by the Session.cookie_path in the php.ini file).
I hope this article will help you with your PHP program design.