Session: In computers, especially in network applications, it is called "session control". Session Object stores the attributes and configuration information required for a specific user session. In this way, when the user jumps between the application's Web pages, the variables stored in the Session object will not be lost, but will persist throughout the user session. When a user requests a Web page from an application, the Web server automatically creates a Session object if the user does not already have a session. When a session expires or is abandoned, the server terminates the session. One of the most common uses of Session objects is to store user preferences. For example, if the user indicates that he or she does not like to view graphics, this information can be stored in the Session object. For more information about using the Session object, see "Managing Sessions" in the "ASP Applications" section. Note Session state is only preserved in browsers that support cookie.
The following is the session usage code:
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.
<?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']; ?>
The above is the detailed content of Add, delete, modify, and view example code of php session. For more information, please follow other related articles on the PHP Chinese website!