search
Homephp教程PHP开发Session state control in PHP (2).

Regarding the PHP tutorial, we talked about cookie parameter passing in the last issue of Zhutou. It was March. This section brings you important session parameter passing.

1. What is session parameter passing?

Session is similar to cookies and is used to store user-related information. For example, common: when you browse different pages of a website, your identity authentication information can be saved, which is achieved by using this parameter.

2. The difference with cookies

session is to store data on the server (through the unique identifier SessionID), while cookies are fragments of information sent by the server to the client, and are stored in the memory of the client's browser or on the hard drive.

3. Session usage steps

1. Set up Session:

This step is very simple, just assign a value to the session variable. For example:

$_SESSION["username"]="Pig's Head";

(Of course, this is the assignment when there is no interaction with the database. In daily development, there is more than one value for Pig's Head, and it is generally replaced by the variable $username)

2 .Read Session:

Use PHP predefined array $_SESSION to obtain, such as:

$_SESSION["username"] ;

3. Delete Session:

Use session_unregister() function to unregister the specified variable. If you want to delete all Session variables, first use session_unset() to release all Session variables, but the SessionID still exists at this time, and we can use session_destroy() to completely destroy it. Such as:

header(“content-Type: text/html; charset=utf-8″);
session_start();
session_unregister(“username”);
session_unset();
session_destroy() ;
header("Refresh:5;url=login_form.php");
echo "You have safely exited the user center";
?>

Note:

Before using session, you must first use session_start () function opens the session and must be placed before all session operations. Otherwise, the session will not be usable.

Conclusion of this section:

Learning PHP, not to mention becoming a PHP master, but mastering basic PHP development technology is still relatively easy, and this will have many benefits for you to modify wordpress, DZ, and dede templates. . If you want to learn, start with the introduction to PHP syntax, dear.

The above is the content of session state control (2) in PHP. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor