Home > Backend Development > PHP Tutorial > Add, delete, modify and view operations of PHP SESSION_PHP tutorial

Add, delete, modify and view operations of PHP SESSION_PHP tutorial

WBOY
Release: 2016-07-13 10:01:29
Original
994 people have browsed it

Add, delete, modify and view operations of PHP SESSION

This article mainly introduces the add, delete, modify and view operations of PHP SESSION. This article directly gives operational examples. , friends in need can refer to it

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 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 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:

The code is as follows:


header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, regardless of session
session_start();//Start saving session data
$_SESSION['name']="xuning";*//Add session data.
?>
Deletion of session data.

The code is as follows:


header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, regardless of 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.

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971945.htmlTechArticleAdd, delete, modify and view operations of PHP SESSION. This article mainly introduces the addition, deletion and viewing of PHP SESSION. Modify and view operations, this article directly gives operation examples, friends in need can...
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