Home  >  Article  >  Backend Development  >  What is the usage of php $_session

What is the usage of php $_session

coldplay.xixi
coldplay.xixiOriginal
2020-11-13 11:16:383103browse

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" ;].

What is the usage of php $_session

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[&#39;keyword&#39;]= "php";
?>

The session in other pages, for example:

<?php
session_start();
echo $_SESSION[&#39;keyword&#39;];
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more