Php's understanding of cookies and sessions

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to understand the cookie: cookie is a gift from the server to the client (small dessert ), one way to complete Server Authentication for users is to use the setCookie function to store the server in the browser of the client when the user logs on to the server.

Welcome to the Linux community forum and interact with 2 million technical staff> understanding cookie: cookie is a gift (small dessert) left by the server to the client ), one way to complete Server Authentication for users is to use the setCookie function to store the server in the browser of the client when the user logs on to the server.

Welcome to the Linux community forum and interact with 2 million technicians>

Understanding of cookies: cookies are a gift (small dessert) left by the server to the client to complete Server Authentication for the user. Specifically, when a user logs on to the server, the server uses the setCookie function to store some identification data (user name, password, logon or not) in the browser of the client ). When the same user accesses other web pages of the site, 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.

Understanding of the session: the session is a verification method for storing personal information on the server, but there is also a way to connect to the client, therefore, there are two different url-based and cookie-based session methods.

Session_start ()

Session_id ()

$ _ SESSION: The functions of these sessions are fully understood. When session_start () is executed, the session_id () value is generated; otherwise, the echo session () is output (); no results. In addition, the values in the $ _ SESSION created at this time, such as $ _ 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, it will be better, the current value in the $ _ SESSION 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, understanding the cookie-based or url-based session based on this idea will make you better understand it.

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.