Home > php教程 > PHP开发 > body text

Session state control in PHP (2).

黄舟
Release: 2016-12-20 11:16:39
Original
1245 people have browsed it

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)!


Related labels:
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!