Add, delete, modify, and view example code of php session

怪我咯
Release: 2023-03-13 15:44:01
Original
1913 people have browsed it

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[&#39;name&#39;]="xuning";*//添加session数据。  
?>
Copy after login

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[&#39;name&#39;]="xuning");*//删除session数据。  
    session_destory();//删除所有的session  
?>
Copy after login

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[&#39;name&#39;];  
?>
Copy after login
Both cookies and sessions end with a session, that is, close the browser to end a session.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!