Home > Article > Backend Development > How to modify php session
The modification of php session is the addition of session data. The modification method is: first save the session data through "session_start"; then add the session through "$_SESSION['name']="xuning";" Just data.
Recommended: "PHP Video Tutorial"
Add, delete, modify, and view PHP SESSION Operation
The difference between SESSION and COOKIE is that the cookie file is saved on the client, while the session is saved on the server. In comparison, in order to improve certain security, session 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, and the security is obvious.
Moreover, session is relatively more powerful and can save arrays and even objects. To some extent, it can reduce development costs.
The following is the usage code of session:
Increase of session data:
The code is as follows:
<?php header("Content-type: text/html; charset=utf-8;");//以utf-8显示,与session无关 session_start();//开始session数据保存 $_SESSION['name']="xuning";*//添加session数据。 ?>
Deletion of session data.
The code is as follows:
<?php header("Content-type: text/html; charset=utf-8;");//以utf-8显示,与session无关 session_start();//开始session数据 unset($_SESSION['name']="xuning");*//删除session数据。 session_destory();//删除所有的session ?>
The modification of session is the increase of session data.
Viewing session data, that is, taking out session data.
The code is as follows:
<?php session_start(); print_r($_SESSION);//获取session echo $_SESSION['name']; ?>
Both cookies and sessions end with a session, that is, closing the browser ends a session.
The above is the detailed content of How to modify php session. For more information, please follow other related articles on the PHP Chinese website!