Home > Backend Development > PHP Problem > How to modify php session

How to modify php session

藏色散人
Release: 2023-03-07 16:38:01
Original
2747 people have browsed it

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.

How to modify php session

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[&#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, 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!

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