Php knowledge about cookies and Sessions

Source: Internet
Author: User
Php's understanding of cookies and Sessions: cookies are a gift (small dessert) left by the server to the client ), specifically, when a user logs on to the server, the server saves some php's understanding about cookies and sessions in the browser of the client through the setCookie function.

Cookie comprehension:
Cookie is a gift (small dessert) left by the server to the client to complete the server's authentication of the user.
Specifically, when a user logs on to the server, the server uses the setCookie function in the browser of the client.
It contains some identification data (user name, password, logon or not ). Wait until the same user accesses the site

In other web pages, the server will determine whether the behavior of the same user is based on the data.

In addition, the key function setCookie () is used to reuse cookies. Therefore, the cookie application is quite simple.


Session comprehension:

The first note is that session is a verification method for saving personal information on the server side, but there is also a way to connect with the client.

So there are two different url-based and cookie-based session methods.

Session_start ()

Session_id ()

$ _ SESSION

The functions of these numbers are fully understood.
When session_start () is executed, the value of session_id () is generated; otherwise, echo session () is output; no result is returned.
In addition, the value in the $ _ SESSION created at this time, for example, $ _ SESSION ["name"] = "zhangsan"; $ _ SESSION ["age"] = 23;
These values will be associated with session_id (), for example, members in a group.
When you jump 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 the same as the previous one, then the current $ _ SESSION
The value in the array is still a member of the original group. If the system does not find session_id, sorry, I have to create another
Session_id, but this is another group. it has nothing to do with the original session_id or $ _ SESSION. Based on this idea
Understanding the cookie-based or url-based session will make you better understand ^ _ ^ |

I recommend an article to help you understand the http://www.jz123.cn/text/196.html.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.