Session function of PhP4 (1)

Source: Internet
Author: User

PhP4 is added with session support over php3. I used it a little bit. For its function interface, internal mechanism,
I have a rough understanding of the ease of application.
The meaning of a session should be clear. A session can contain HTTP requests and responses several times,
For example, if we use 163.net, from login to logout or timeout, we use it as a session, session
Generally, a unique session ID is generated within the system.
String. In addition to the session ID, a session can also have its own session data.
Record and differentiate different states of the sesion.

PhP4 provides the following APIs 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

Meaning you can understand at a glance that session_start starts a session and session_destroy ends
End a session, session_id to get the current session_id, session_register to the current
Session to register a variable. This is very useful, for example, when a user visits a mall and selects a few items for you.
You can use session_register to set the product name orCodeRegister to the current session.

For example, the following example (from PhP manual ):

<? PHP
Session_register ("count ");
$ Count ++;
?>

Hello visitor, you have seen this page <? Echo $ count;?> Times. <p>
# The <? = Sid?> Is necessary to preserve the session ID
# In the case that the user has disabled cookies

To continue, <a href = "nextpage. php? <? = Sid?> "> Click here </a>

Session_register can implicitly stimulate session_start (if the user has not sent a session before _
The current session registers a variable count. Each time you click here
This variable will be added. You can try it on your own. <? = Sid?> The meaning is not repeated.

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.