Thinkphp _php Example of Session () method usage

Source: Internet
Author: User
Tags session id php template codeigniter zend framework

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

The system provides the session management and operation of the perfect support, all operations can be completed through a built-in session function.


Session (Name,name,value= ')


Name (required): If an incoming array indicates session initialization, if passing in null indicates emptying the current session, a string represents the session assignment, fetch, or operation.
Value (optional): The session value to set, if passing in NULL indicates a session deletion, the default is an empty string

Session Initialization settings

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

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

The system starts the session automatically after initialization, and you can set Session_auto_start to False if you do not want the system to start the session automatically

For example:

' Session_auto_start ' =>false

Turn off the public files that can be project after automatic startup or start the session in the Controller by manually calling Session_Start or session (' [Start] ').

Session Assignment

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

Session Take value

$value = Session (' name ');

Session deletion

Session (' name ', null); Delete Name

To remove all sessions, you can use:

session (NULL); Empty 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, using the following:

Session (' [Operation name] ');
Session (' [Pause] '); Pause Session Write Session
(' [start] ');/start session session
(' [Destroy] ');/destroy Session session (' [
Regenerate ]'); Regenerate session ID

PHP has its own function session_unset. the effect is to clear (release) All session variables, and if you need to clear a certain conversation variable, you should use the

unset ($_session[' var ']);

More interested readers of thinkphp related content can view the website topic: "thinkphp Introductory Course", "thinkphp template Operation Skill Summary", "thinkphp Common Method Summary", "The CodeIgniter Introductory Course", "CI ( CodeIgniter) Framework Advanced tutorials, introductory tutorials for the Zend framework Framework, Smarty Templates Primer tutorial, and PHP template technology summary.

I hope this article will help you with the PHP program design based on thinkphp framework.

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: 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.