Home > Article > Backend Development > Add, delete, modify and view operations of PHP SESSION, phpsession_PHP tutorial
The difference between SESSION and COOKIE is that first of all, the cookie file is saved on the client, while the session is Compared with those stored on the server, in order to improve a certain level of security, session has more advantages.
Because 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 it is not specified, the password is also saved in clear text, so the security is obvious.
And session is relatively more powerful and can save arrays and even objects. To some extent, it can reduce development costs.
The following is the session usage code:
Increase of session data:
Copy code The code is as follows:
Header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, has nothing to do with session
Session_start();//Start saving session data
$_SESSION['name']="xuning";*//Add session data.
?>
Deletion of session data.
Copy code The code is as follows:
Header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, has nothing to do with session
Session_start();//Start session data
Unset($_SESSION['name']="xuning");*//Delete session data.
Session_destory();//Delete all sessions
?>
The modification of session is the addition of session data.
Viewing session data means taking out session data.
Copy code The code is as follows:
session_start();
print_r($_SESSION);//Get session
echo $_SESSION['name'];
?>
Both cookies and sessions end with a session, that is, closing the browser ends a session.