Home > Article > Backend Development > What is the usage of php $_session
php $_session usage: 1. Initialize the session variable, the code is [session_start();]; 2. Write and read the session, the code is [$_SESSION['keyword']= "php" ;].
php $_session usage:
When using PHP to apply a session, store the data in the session on the server , and then identify the client's information through the sessionID passed by the client, and extract the information.
Common operations of session in php: writing, reading, registering and deleting session.
Start of session
The function that marks the start of session use is session_start
, and the session_start
function is used to initialize session variables. The syntax is as follows:
session_start();
The return value is TRUE.
Writing and reading of session
In PHP, the use of session is completed by calling and reading the predefined array $_SESSION
.
In the website page, assign the $_SESSION
array on the registration page, and read the $_SESSION
array on other pages.
The session in the registration page, for example:
<?php session_start(); $_SESSION['keyword']= "php"; ?>
The session in other pages, for example:
<?php session_start(); echo $_SESSION['keyword']; ?>
Run in sequence, the result is:
php
Related free learning recommendations: php programming (video)
The above is the detailed content of What is the usage of php $_session. For more information, please follow other related articles on the PHP Chinese website!