thinkphp Function: Session method

Source: Internet
Author: User
Tags session id

The session method is used for session setup, get, delete, and manage operations.

Session for session settings, get, delete, and manage operations
Usage Session ($name, $value = ")
Parameters Name (required): If the incoming array is a session initialization, if NULL is passed in to empty the current session, the string indicates the session assignment, fetch, or operation.
Value (optional): The session value to be set, if the null is passed in to delete the session, the default is an empty string
return value See details (return different values depending on the specific usage)

The session function is a diversified operation function, which can accomplish different functions by passing in different parameter calls, including some of the following functions.

Session Initialization settings

If the name parameter of the session method is passed in the array, the session initialization setting is used, for example:

Session (array(' name ' = ' session_id ', ' expire ' =>3600));

Support for incoming session parameters includes:

Td>session hander type, you can use the hander driver extension
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.c Ookie_domain Setting value
use_cookies session.use_cookies setting value
use _trans_sid session.use_trans_sid setting value
cache_limiter session_cache_limite R setting value
cache_expire session_cache_expire setting value
type

SESSION initialization setting method does not need to call manually, after the initialization of the app class is called automatically, usually the project only needs to configure the Session_options parameter, the Session_options parameter is set to an array, The supported index names are the same as the previous session initialization parameters.
By default, the system will automatically start 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:

' Session_auto_start ' =false

Turn off the session by manually invoking Session_Start or session (' [Start] ') on the project's public file or in the controller after auto-start.

Session Assignment

The session assignment is relatively straightforward and is used directly:

Session (' name ', ' value ');  // Set Session

Equivalent:

$_session [' name '] = ' value ';
Session Fetch Value

Session value using:

$value = Session (' name ');

Equivalent to using:

$value $_session [' Name '];
Session Delete
Session (' name ',null//  Delete name

Equivalent:

unset ($_session[' name ']);

To delete all the sessions, you can use:

Session (NULL//  Empty the current session

Equivalent:

$_session Array ();
Session Judgment

To determine if a session value has been set, you can use the

Session ('? name ');

Used to determine if the session value named name is already set
Equivalent:

isset ($_session[' name ']);
Session Management

The session method supports some simple session management operations with the following usage:

Session (' [Operation name] ');

The supported operation names are:

Action name meaning
Start Start session
Pause Pause Session Write
Destroy Destroy session
Regenerate Regenerate session ID

Examples of use are:

// Pause Session Write // Start Session // Destroy Session // Regenerate session ID
Localization support

Localized session management support can be enabled if you pass in the prefix parameter when initializing the session setting or if the Session_prefix parameter is set individually. After the localization session is started, all assignments, values, deletions, and judgments will automatically support localization sessions.
After localization session support is turned on, the generated session data format is changed from the original $_session[' name '] to the $_session[' prefix ' [' name ']

Assuming the prefix is set to think, the assignment operation: session (' Name ', ' value ');//Set Sessionequivalent to:$_session[' Think '] [' name '] = ' value '; Value operation:$value= Session (' name '); equivalent to using:$value=$_session[' Think '] [' Name ']; Delete operation: Session (' Name ',NULL); equivalent to:unset($_session[' Think '] [' Name ']); empty operation: Session (NULL); Equivalent to:unset($_session[' Think ']); Judgment operation: Session ('? Name '); equivalent to:isset($_session[' Think '] [' name ']);

thinkphp Function: Session method

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.