Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use session in thinkphp5

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use session in thinkphp5". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use session in thinkphp5.

In thinkphp5, the session method is used to set, get, delete and manage Session. It is a diversified operation function. Different parameter calls can be passed in to complete different functional operations. The syntax is "session ($name, $value='')".

This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.

What is the use of session in thinkphp5

The Session method is used to set, get, delete, and manage Session operations.

Usage

Session ($name, $value='')

Parameter name (required): session initialization is performed if an array is passed, current session is cleared if null is passed, and session assignment, acquisition or operation is performed if it is a string.

Value (optional): the session value to be set. If null is passed, the session is deleted. The default is empty string.

The session function is a diversified operation function, and different parameter calls can complete different functions, including some of the following functions.

Session initialization Settings

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

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

The Session initialization setting method does not need to be called manually, but will be called automatically after the initialization of the App class. Usually, the project only needs to configure the SESSION_OPTIONS parameter. The setting of the SESSION_OPTIONS parameter is an array, and the supported index name is the same as the previous session initialization parameter.

By default, the system starts session automatically after initialization. If you do not want the system to start session automatically, you can set SESSION_AUTO_START to false, for example:

'SESSION_AUTO_START' = > false

After turning off automatic startup, you can start session by manually calling session_start or session ('[start]') in the controller or the public file of the project.

Session assignment

Session assignment is relatively simple, and can be used directly:

Session ('name','value'); / / set session

Equivalent to:

$_ SESSION ['name'] =' value'

Session value

The value of Session is as follows:

$value = session ('name')

It is equivalent to using:

$value = $_ SESSION ['name']

Session deletion

Session ('name',null); / / Delete name

Equivalent to:

Unset ($_ SESSION ['name'])

To delete all session, you can use:

Session (null); / / clear the current session

Equivalent to:

$_ SESSION = array (); at this point, I believe you have a better understanding of "how to use session in thinkphp5". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report