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