The use of the session () method in thinkphp

Source: Internet
Author: User
This article mainly introduces the use of the session () method in thinkphp, and analyzes the function, parameters, specific use methods and related precautions of the session method in the thinkphp with the example form, and the friends who need can refer to the following

This example describes the session () method usage in thinkphp. Share to everyone for your reference, as follows:

The system provides perfect support for session management and operation, all of which can be completed by a built-in session function.

Usage

Session (name,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

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));

After initialization, the system will automatically start the session, 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

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

Session Fetch Value

$value = Session (' name ');

Session Delete

Session (' name ', null); Remove name

To delete all the sessions, you can use:

session (NULL); Clear the current session

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

Session Management

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

Session (' [Operation name] '); session (' [Pause] '); Pause Session Write session (' [Start] '); Start Sessionsession (' [Destroy] '); Destruction of Sessionsession (' [Regenerate] '); Regenerate session ID

PHP comes with a function session_unset. the function is to clear (release) All session variables, and if you need to clear a session variable, you should use the

unset ($_session[' var ');

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.