[PHP learning log] Simple Session usage

Source: Internet
Author: User
[PHP learning logs] the use of simple Sessions first provides some explanations of Sessions: Currently, the most practical network protocol is HTTP Hypertext Transfer Protocol, which is & ldquo; stateless & rdquo; the so-called & ldquo; stateless & rdquo; refers to the & ldquo; Status & rdquo; in which the user and the server do not need to be stored for interaction ;. Session is the use of & ldquo; Session Control & rdquo; [PHP learning log] Simple Session in network applications

First, let's explain some Session explanations: Currently, the most practical network protocol is HTTP Hypertext Transfer Protocol, which is "stateless, the so-called "stateless" refers to the "state" in which the user does not store the interaction when interacting with the server ". Session is the "Session control" module in network applications. Therefore, the Session object stores the information required for a specific user Session, that is, the previously mentioned "status" information. In this way, when a user jumps between Web pages of an application, the variables stored in the Session object will not be lost, but will continue to exist throughout the user Session, in this way, the user interacts with the server.

Here I learned how to use PHP sessions, so I first pasted a piece of code:

1

The session is directly enabled here. when this method is called, the server will identify whether a session already in use exists. If yes, the server will directly call this session. If no session exists, the server restarts a session and specifies a unique ID for it. Is the reliability of a session guaranteed? (That is, we need to enable the same session on different PHP pages) the answer is yes. The system will call "session_start () the session with the same ID is used. Then I will post a piece of code:

1 
 

It can be seen that this code differs from the previous code by calling the "session_id ()" method. Here, the "session_id ()" method has two functions:

  • Enable session with the specified id
  • Obtain the id of the currently enabled session

Here, we obviously enable this session by specifying an id = id enabling method. the advantage is that session calls are more stable. (It is not recommended to do this directly. you can use cookies to store session IDs for stable session calls)

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.