Home >Backend Development >PHP Tutorial >The difference between Cookie and Session_PHP Tutorial

The difference between Cookie and Session_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:25:00861browse

The http protocol is a stateless connection. If you want to track user behavior, you must have a variable that can work on a different page. In PHP, it can be implemented using cookies and sessions.
Everyone is familiar with cookies. They just save variables as a file on the client. However, if the client prohibits cookies, there is nothing you can do. This requires session. In PHP4, session can be implemented in two ways. One is to use cookies, that is, save the session ID in the cookie file; the other is to attach the session ID to the URL and pass it.
Although there are two ways to achieve this, programmers don’t need to worry about which method to use. PHP will automatically check the client’s cookie settings (referring to linux/unix platforms, unknown to Win32), and the default is to use it first. cookie (you can modify the value of session.use_cookies in the [session] section of the php.ini file to change it). Of course, you can also force the use of URL to pass SessionID, as follows:
">Submit form
Just add a =sessionID;?> to the link. Simple, right? There are many settings about Session in php.ini , such as session.cookie_lifetime is the valid time of the session, etc., are all in the [session] section. If you look at it, you will have a better understanding of the session in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532091.htmlTechArticleThe http protocol is a stateless connection. If you want to track user behavior, you must have a system that can work on different Page variables can be implemented in PHP using two methods: cookie and session. co...
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