Session_id () to access the current session code.
Syntax: String session_id (string [ID]);
This function can obtain or reconfigure the current session code. If no parameter ID is provided, only the current session code is obtained. If the parameter is added, the session code is set to the new specified ID. The input and return parameters are strings.
Output session_id ()
<? Phpsession_start (); echo session_id (); // output dqr58dnuqj2gufvg4o3tmjb9v4?> <? Phpsession_id ("nowamagic"); session_start (); echo session_id (); // output nowamagic?>Session_id resume session content
PHP session can be recovered by the program, which is not the same as Java. The session recovery mechanism can be used to share sessions of multiple applications, because PHP sessions are stored in the form of files or databases. First, the session_id is obtained through the session_id () function. This value can be passed.
To resume a session, you must first know the session_id. You can use the manual to know that the session is restored by session_id ($ id). However, you must pay attention to the sequence when restoring the session, to obtain the content of the previous session, you must execute session_id ($ id) before session_start () so that the previous content can be restored when the session is initialized when session_start is executed, otherwise, you will get an empty session and you will not get anything. Previously, the session was reinitialized. This is closely related to the role of session_start (), because session_start tells PHP that the session should be initialized and deserialized from the session file, therefore, session_start is used to deserialize the previously stored file content. Before serialization, session_start needs to know the session_id. If no session_id is generated, a new one is generated. If yes, deserialize the content of the corresponding file.
Session_id resume session content