What is the usage of php $_session

coldplay.xixi
Release: 2023-03-07 15:28:02
Original
3100 people have browsed it

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();
Copy after login

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";
?>
Copy after login

The session in other pages, for example:

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

Run in sequence, the result is:

php
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!