session_reset
(PHP 5 >= 5.6.0, PHP 7, PHP 8)
session_reset — Re-initialize session array with original values
说明
session_reset(): boolsession_reset() reinitializes a session with original values stored in session storage. This function requires an active session and discards changes in $_SESSION.
参数
此函数没有参数。
返回值
成功时返回 true
, 或者在失败时返回 false
。
更新日志
参见
$_SESSION The session.auto_start configuration directive session_start() - 启动新会话或者重用现有会话 session_abort() - Discard session array changes and finish session session_commit() - session_write_close 的别名
User Contributed Notes 2 notes
up down 31 parsa dot mhn at outlook dot com ¶6 years ago
First of all you should execute this code :
<?php
session_start();
$_SESSION["A"] = "Some Value";
?>
then you should execute this one :
<?php
start_session();
$_SESSION["A"] = "Some New Value"; // set new value
session_reset(); // old session value restored
echo $_SESSION["A"];
//Output: Some Value
?>
That is because session_reset() is rolling back changes to the last saved session data, which is their values right after the session_start().
up
down
-29
vijay dot mits at gmail dot com ¶7 years ago
first create a session variable
<?php
session_start();
$_SESSION["A"] = "Some Value";
echo $_SESSION["A"];
//Output: Some Value
//if you need to rollback the session values after seting new value to session variables use session_reset()
$_SESSION["A"] = "Some New Value"; // set new value
session_reset(); // old session value restored
echo $_SESSION["A"];
//Output: Some Value
?>
add a note
官方地址:https://www.php.net/manual/en/function.session-reset.php