The difference between a session and a cookie is that the file of the cookie is stored on the client, and the session is saved in the server, in order to improve security, the session has advantages.
Because the session on the server side of the general situation is the management of the server, but cookies are saved in the client, anyone can see, if not specified, password is also clear, security is obvious.
And the session is relatively more powerful, you can save the array, and even objects, in a way, can reduce the development costs.
Here is the use code for the session:
Increase in session data:
Copy Code code as follows:
<?php
Header ("content-type:text/html; Charset=utf-8; "); /UTF-8 Display, not session-independent
Session_Start ()//Start session data Save
$_session[' name ']= ' xuning '; *//add session data.
?>
deletion of session data.
Copy Code code as follows:
<?php
Header ("content-type:text/html; Charset=utf-8; "); /UTF-8 Display, not session-independent
Session_Start ()//Start session data
unset ($_session[' name ']= "xuning"); *//Delete session data.
Session_destory ()//Delete all sessions
?>
Session modification is the increase in session data.
The session data is viewed, that is, the session data is removed.
Copy Code code as follows:
<?php
Session_Start ();
Print_r ($_session);//Get session
echo $_session[' name '];
?>
Whether a cookie or session ends with a conversation, closing the browser closes a session.