Session Operations in PHP
AI summary
文章介绍了 PHP session 的基本操作,包括启动会话、存储和取出 session 变量、删除单个 session 变量和彻底销毁 session。文章强调了在存储用户信息前必须启动会话,并提供了相关代码示例。核心观点是 session 是一种在服务器端存储用户数据的机制,通过 session_start() 启动会话,使用 $_SESSION 存储和访问数据,并通过 unset 和 session_destroy() 进行数据管理。彻底销毁 session 会重置所有 session 数据。
Repost license
Request authorization before reposting and retain the authorization code, original URL, and go/affiliate links.
Original URL:https://www.geekcorelab.com/post/session-operations-in-php
The commercial link is an authorized go short link that must stay on the reposted page. It records the source before sending readers to the original article.
Start PHP Session
Before you can store user information in a PHP session, you must first start a session
<?php
session_start();
?>
Store Session Variables
<?php
$_SESSION['UserName']='gqink';
?>
Retrieve Session Variables
<?php
echo $_SESSION['UserName'];
?>
Delete Session
<?php
unset($_SESSION['UserName']);
?>
Completely Destroy the Session
<?php
session_destroy();
?>
session_destroy() will reset the session, and you will lose all stored session data
Comments
Discussion
Be kind and keep the discussion friendly.
Discussion
0 comments