PHP4 has new session support than PHP3. After using it for a while, I got a general understanding of its function interface, internal mechanism, and
convenience of application.
Everyone should know the meaning of session. A session can include several http requests and responses.
For example, if we use 163.net, from login to logout or timeout is regarded as a session. The only thing about session
The identification is generally a unique session ID generated within the system, which is usually a very long
string. In addition to the session ID, a session can also have its own session data, which can
record and distinguish different statuses of the session.
php4 provides the following interfaces for session operations:
session_start — Initialize session data
session_destroy — Destroys all data registered to a session
session_name — Get and/or set the current session name
session_module_name — Get and/or set the current session module
session_save_path — Get and/or set the current session save path
session_id — Get and/or set the current session id
session_register — Register a variable with the current session
session_unregister — Unregister a variable from the current session
session_is_registered — Find out if a variable is registered in a session
session_decode — Decodes session data from a string
session_encode — Encodes the current session data as a string
The meaning can be understood at a glance. session_start starts a session, session_destroy ends
ends a session, session_id gets the current session_id, and session_register registers with the current session
A variable, this is very useful. For example, when a user visits a mall and selects certain products, you
can use session_register to register the product name or code into the current session.
For example, the following example (extracted from php manual):
session_register("count");
$count++;
?>
Hello visitor, you have seen this page echo $count; ?> times.
# the =SID?> is necessary to preserve the session id
# in the case that the user has disabled cookies
To continue, click here
session_register can implicitly trigger session_start (if the user has not issued a session_
start call before). The current session registers a variable count. Every time the user clicks click here
, this variable will increase by one. You can try it yourself. The meaning of =SID?> is not detailed here.