ThinkPHP function description: session method

Source: Internet
Author: User
The Session method is used to set, obtain, delete, and manage sessions. The Session method is used to set, obtain, delete, and manage sessions.
Sessions are used to set, obtain, delete, and manage sessions.
Usage Session ($ name, $ value = '')
Parameters Name (required): If an array is input, session initialization is performed. If null is input, the current session is cleared. if it is a string, the session value is assigned, obtained, or operated.
Value (optional): The session Value to be set. If null is input, the session is deleted. the default Value is a null string.
Return value See details (return different values based on specific usage)
The session function is a diverse operation function. you can call different parameters to complete different function operations, including the following functions. [-More-] session initialization setting if the name parameter of the session method is input into an array, it indicates the session initialization setting, for example:
  1. Session (array ('name' => 'session _ id', 'expire '=> 3600 ));
The following session parameters supported by the copy code include:
Parameter name Description
Id Session_id value
Name Session_name value
Path Session_save_path value
Prefix Session localized space prefix
Expire Session. gc_maxlifetime setting value
Domain Session. cookie_domain setting value
Use_cookies Session. use_cookies setting value
Use_trans_sid Session. use_trans_sid setting value
Cache_limiter Session_cache_limiter
Cache_expire Session_cache_expire
Type Session hander type, which can be extended using the hander driver
The Session initialization setting method does not need to be manually called. it is automatically called after the initialization of the App class ends. Generally, the project only needs to configure the SESSION_OPTIONS parameter. the SESSION_OPTIONS parameter is set as an array, the index names supported are the same as the previous session initialization parameters.
By default, the system automatically starts the session after initialization. if you do not want the system to automatically start the session, you can set SESSION_AUTO_START to false. for example:
  1. 'Session _ AUTO_START '=> false
Copy the code to close the public file of the project after automatic startup, or manually call session_start or session ('[start]') in the controller to start the session. Session assignment:
  1. Session ('name', 'value'); // sets the session
Copying code is equivalent:
  1. $ _ SESSION ['name'] = 'value ';
Copy code session value Session value usage:
  1. $ Value = session ('name ');
Copying code is equivalent to using:
  1. $ Value = $ _ SESSION ['name'];
Copy code session deletion
  1. Session ('name', null); // delete name
Copying code is equivalent:
  1. Unset ($ _ SESSION ['name']);
To delete all sessions, copy the code:
  1. Session (null); // clear the current session
Copying code is equivalent:
  1. $ _ SESSION = array ();
Copy the code session to determine whether a session value has been set. you can use
  1. Session ('? Name ');
Copy the code to determine whether the session value with the name has been set
Equivalent:
  1. Isset ($ _ SESSION ['name']);
The copy code session management session method supports some simple session management operations. the usage is as follows:
  1. Session ('[operation name]');
The operation names supported by the copy code include:
Operation Name Description
Start Start session
Pause Pause session writing
Destroy Destroy session
Regenerate Regenerate session id
Example:
  1. Session ('[pause]'); // pause session writing
  2. Session ('[start]'); // start the session
  3. Session ('[destroy]'); // destroy the session
  4. Session ('[regenerate]'); // regenerate the session id
Copy code localization supports enabling local session management if the prefix parameter is input during session initialization or the SESSION_PREFIX parameter is set separately. After a localized session is started, all assignment, value, deletion, and judgment operations automatically support the localized session.
After the local session is enabled, the format of the generated session data is changed from
  1. $ _ SESSION ['name'] becomes $ _ SESSION ['prefix'] ['name']
If the prefix of the copied code is set to think, the value assignment operation is performed:
  1. Session ('name', 'value'); // sets the session
Copying code is equivalent:
  1. $ _ SESSION ['think'] ['name'] = 'value ';
Copy the code value operation:
  1. $ Value = session ('name ');
Copying code is equivalent to using:
  1. $ Value = $ _ SESSION ['think'] ['name'];
Copy code delete operation:
  1. Session ('name', null );
Copying code is equivalent:
  1. Unset ($ _ SESSION ['think'] ['name']);
Copy the code to clear:
  1. Session (null );
Copying code is equivalent:
  1. Unset ($ _ SESSION ['think']);
Copy the code to determine the operation:
  1. Session ('? Name ');
Copying code is equivalent:
  1. Isset ($ _ SESSION ['think'] ['name']);
Copy code

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.