Session mechanisms (sessions) are used in PHP to hold some of the data in concurrent access. This makes it possible to help create more humane programs that increase the attractiveness of your site.
A visitor visiting your Web site will be assigned a unique ID, which is called the session ID. This ID can be stored in a cookie on the client side, or it can be passed through a URL.
Session support allows you to save the data in the request in the Hyper-global array $_session. When a visitor visits your website, PHP will automatically check (if Session.auto_start is set to 1) or check (explicitly via session_start () or implicitly through Session_register ()) The current session ID at your request Whether it was a previously sent request creation. If this is the case, then the previously saved 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 session.serialize_handler by this PHP Configuration option to set a specified method. The registered variable is not defined and will be marked as undefined. When concurrent access, these variables are not defined by the session module unless they are later defined by the user.
Because session data is serialized, the resource variable cannot be stored in the session. Serialization handles (PHP and php_binary) are limited by register_globals. Also, the numeric index or string index contains special characters (| and!) that cannot be used. The last error occurs when you use these characters to close the script execution. Php_serialize There is no such restriction. Php_serialize is available from PHP 5.5.4.
Example one, the simple use of the session:
<?php //Register session Session_Start (); if (!isset ($_session[' count '))) { $_session[' count '] = 0; } else { $_session[' count ']++; } Delete SESSION unset ($_session[' count '); ? >
Session Correlation Function:
Session_cache_expire-return Current Cache Expiresession_cache_limiter-get and/or set the current cache Limitersession_ Commit-session_write_close alias session_decode-decodes session data from a session encoded STRINGSESSION_DESTROY-DESTR Oys all data registered to a sessionsession_encode-encode the current session data as a string session_get_cookie_params-get the session cookie par Ameterssession_id-get and/or set the current session idsession_is_registered-check if the variable is already registered in the session Session_module_name-get a nd/or set the current session Modulesession_name-get and/or set the current session Namesession_regenerate_id-update T He current session ID with a newly generated onesession_register_shutdown-session shutdown functionsession_register-re Gister one or more global variables with the current sessionsession_save_path-get and/or set the current session save PA Thsession_set_cookie_params-set the session cookie Parameterssession_set_save_handler-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 Sessionsession_unset-free all session Variablessession_write_close-write session data and End Session
The above is the PHP features of the session mechanism 2--session and its use of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!