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.