PHP features-Session mechanism 2-Session and usage

Source: Internet
Author: User
Session mechanism (Session) is used in PHP to save some data in concurrent access. This allows you to create more user-friendly programs and increase the attractiveness of your site. Session mechanism (Session) is used in PHP to save some data in concurrent access. This allows you to create more user-friendly programs and increase the attractiveness of your site.
A visitor will be assigned a unique id to access your web site, which is a session id. this id can be stored in a cookie on the user side or transmitted through a URL.
SESSION support allows you to save the data in the request in the ultra-Global Array $ _ SESSION. when a visitor accesses your website, PHP will automatically check (if session. auto_start is set to 1) or check (explicitly through session_start () or implicitly through session_register () whether the current session id is created in the previous request. in this case, the previously stored environment will be rebuilt.
$ _ SESSION (and all registered variables) will be serialized by PHP using the built-in serialization method when the request is complete. the serialization method can be implemented through session. serialize_handler sets a specified method in the PHP configuration option. registered variable undefined will be marked as undefined. during concurrent access, these variables are not defined by the session module unless they are later defined by the user.
Because session data is serialized, resource variables cannot be stored in sessions. serialization handles (php and php_binary) are restricted by register_globals. in addition, the numeric index or string index contains special characters (| and !) Cannot be used. The final error occurs when these characters are used to close the script execution. php_serialize does not have such restrictions. php_serialize is available after PHP 5.5.4.
Example 1: Simple session usage:

 

Session functions:

Your-Return current cache has-Get and/or set the current cache has-session_write_close alias session_decode-Decodes session data from a session encoded sessions-Destroys all data registered to a sessionsession_encode-will the current session data is encoded as a string session_get_cookie_params-Get the session cookie parameterssession_id-Get and/or set the current session idsession_is_registered-check whether the variable has registered session_module_name-Get and/or set the current session modulesession_name-Get and/or set the current session namesession_regenerate_id-Update the current session id with a newly generated partition-Session shutdown functionsession_register-Register one or more global variables -Get and/or set the current session save failed-Set the session cookie reset-Sets user-level session storage functionssession_start-Start new or resume existing sessionsession_status-Returns the current session statussession_unregister-Unregister a global variable from the current sessionsession_unset-Free all session variablessession_write_close-Write session data and end session

The above is PHP's Session mechanism 2-Session and its usage. For more information, see PHP's Chinese website (www.php1.cn )!

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.