Add, delete, modify, and view PHPSESSION

Source: Internet
Author: User
This article describes how to add, delete, modify, and view PHP sessions. This article describes how to operate an instance. if you need a SESSION, you can refer to the differences between SESSION and COOKIE. First of all, cookie files are stored on the client, while Sessions are stored on the server. session is more advantageous to improve security.

The session is generally managed by the server administrator on the server side, but the cookie is saved on the client side and can be viewed by anyone. If this parameter is not specified, the password is also saved in plaintext, security is obvious.

In addition, sessions are relatively more powerful and can save arrays and even objects. To some extent, they can reduce development costs.

The following is the session usage code:

Session Data increase:

The code is as follows:


<? Php
Header ("Content-type: text/html; charset = utf-8;"); // it is displayed in UTF-8 and has nothing to do with session
Session_start (); // start session data storage
$ _ SESSION ['name'] = "xuning"; * // add session data.
?>


Delete session data.

The code is as follows:


<? Php
Header ("Content-type: text/html; charset = utf-8;"); // it is displayed in UTF-8 and has nothing to do with session
Session_start (); // start session data
Unset ($ _ SESSION ['name'] = "xuning"); * // deletes session data.
Session_destory (); // delete all sessions
?>

The modification of the session is the addition of the session data.
View session data, that is, retrieve session data.

The code is as follows:


<? Php
Session_start ();
Print_r ($ _ SESSION); // Get the session
Echo $ _ SESSION ['name'];
?>

Both cookie and session end with one session, that is, close the browser to end one session.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.