First, what is the session
- The session begins with the user access page, to the point where the connection to the site is disconnected, forming the life cycle of a conversation. During a session, the client is assigned a unique SessionID that identifies the current user and distinguishes it from other users.
- Session, SessionID will be stored on both the client and server side two locations, for the client to use a temporary cookie to save (cookie name is called PHPSESSID) or through a URL string passed, The server side is also saved as a text file in the specified session directory.
- The session receives each access request through the ID, thus identifying the current user, tracking and maintaining the user's specific data, and session variables (which can be stored in the session during the session for digital or textual data), such as session_name, etc. These variable information is stored on the server side.
- SessionID can be saved as session information in the database, and the session can be persisted, so as to track each user's login times, online or not, online time, etc.
Second, the basic steps to use the session:
- Start session
- session_start () starts a session or returns a session that already exists.
- Registering Session Variables
- Using Session Variables
- Unregister variables and destroy sessions
- Logout Example:
- To destroy a session:
- The Session_unset () function clears all variables stored in the current session, which effectively resets the session to the state it was created in.
- The Session_destroy () function completely removes the session from the storage mechanism, invalidating the current session.
Third, the difference between the cookie and session:
- Both cookies and sessions can temporarily hold variables used in multiple pages, but they differ in nature:
- Cookies are stored in the client browser;
- Session is saved on the server;
- The link between them is that the session ID is usually stored in a cookie or placed on a URL.
Session Tracking Technology--session