CakePHP Session Management - CakePHP

What is CakePHP Session Management?

Session permits us to manipulate particular users throughout requests and stores information for unique users. consultation information may be accessible anywhere anywhere in which you have get admission to to request item, i.e., sessions are on hand from controllers, views, helpers, cells, and components.

Having Access To Consultation Item

Consultation object can be created by way of executing the subsequent code.

Writing Consultation Records

To write some thing in consultation, we can use the write() session technique.

The above method will take two arguments, the price and the important thing beneath which the price could be saved.

Example

Reading Session Statistics

To retrieve stored statistics from consultation, we are able to use the examine() session technique.

The above feature will take most effective one argument this is the important thing of the fee which became used on the time of writing session facts. as soon as the proper key was furnished then the function will return its cost.

Example

While you want to check whether or not precise facts exists in the consultation or now not, then you can use the check() session approach.

The above function will take only key as the argument.

Example

Delete Session Information

To delete information from session, we can use the delete() consultation approach to delete the records.

The above function will take most effective key of the price to be deleted from session.

Example

while you want to examine after which delete facts from consultation then, we will use the consume() consultation method.

The above characteristic will take simplest key as argument.

Example

Destroying A Consultation

We want to damage a consumer consultation while the person logs out from the website online and to ruin the session the ruin() method is used.

Example

Destroying consultation will do away with all session statistics from server but will now not cast off session cookie.

Renew A Session

In a state of affairs where you want to resume user consultation then we are able to use the renew() consultation approach.

Example

Complete Session

config/routes.php

Create a SessionsController.php file at src/Controller/SessionsController.php. replica the following code inside the controller file.
src/Controller/SessionsController.php

Create a directory periods at src/Template and below that listing create a View record referred to as write_session_data.ctp. replica the following code in that report.
src/Template/Sessions/write_session_data.ctp

Create every other View document called retrieve_session_data.ctp below the identical sessions listing and copy the subsequent code in that document.
src/Template/Sessions/retrieve_session_data.ctp

Create some other View file called check_session_data.ctp under the identical classes directory and copy the subsequent code in that report.
src/Template/Sessions/check_session_data.ctp

Create another filbe View referred to as delete_session_data.ctp below the equal classes listing and replica the following code in that report.
src/Template/Sessions/delete_session_data.ctp


Create some other View document known as destroy_session_data.ctp underneath the equal periods directory and duplicate the following code in that document
src/Template/Sessions/destroy_session_data.ctp

Output

Execute the above instance with the aid of traveling the subsequent URL. This URL will help you write statistics in consultation.
sm-1
visit the subsequent URL to read session records − http://localhost:85/CakePHP/session-read
sm-2

go to the following URL to check consultation records − http://localhost:85/CakePHP/sessioncheck
sm-3

go to the following URL to delete session statistics − http://localhost:85/CakePHP/sessiondelete

sm-4

visit the following URL to spoil session records − http://localhost:85/CakePHP/sessiondestroy

sm-5

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CakePHP Topics