Home >Backend Development >PHP Tutorial >PHP about understanding cookies and sessions_PHP tutorial

PHP about understanding cookies and sessions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:48:41910browse

Understanding of cookies:
Cookies are gifts (little desserts) left by the server to the client as a way to complete the server's authentication of the user
Specifically speaking, when the user logs in to the server, the server uses the setCookie function to set the cookie in the client's browser
It stores some data that can indicate your identity (user name, password, logged in or not). Wait until the same user visits the site

When browsing other web pages, the server will use this data to determine whether it is the behavior of the same user.

In addition, when using cookies, there is a key function setCookie(); so the application of cookies is quite simple


Understanding of session:

The first thing to explain is that session is a verification method that saves personal information on the server side, but there is also a way to connect to the client

, so there are two different session methods based on cookies and url-based.

session_start()

session_id()

$_SESSION

You must fully understand the functions of these numbers
When session_start() is executed, the value of session_id() will be generated, otherwise echo session(); will be output and there will be no result
In addition, the value in $_SESSION created at this time, such as $_SESSION["name"]="zhangsan";$_SESSION["age"]=23;
These values ​​will be together with the session_id(), such as the members in a group.
When jumping to another interface, the first step is to execute session_start().
At this time, the system will determine whether there is an existing session_id. If there is and it is the same as the previous one, then okay, the current $_SESSION
The values ​​in the array are still the members of the original group. Thoughts: If the system does not find the session_id, then I'm sorry, I have to create another one
session_id But this is another group. It has nothing to do with the original session_id or $_SESSION. According to this idea
If you understand the session based on cookie or URL, you will understand it better^_^||


I would like to recommend another article to help you understand more http://www.BkJia.com/net/200410/1666.html

Excerpted from Starting from small steps can achieve great things

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478398.htmlTechArticleUnderstanding of cookies: Cookies are gifts (little desserts) left by the server to the client to complete the server's request to the user Specifically speaking, one way of authentication is that when a user logs in...
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