Current Location: Home> Function Categories> session_reset

session_reset

Reinitialize the session array with the original value
Name:session_reset
Category:Session Session
Programming Language:php
One-line Description:All session variables will be reinitialized and the session pointer will be moved to the beginning of the session array

Function name: session_reset()

Applicable version: PHP 5 >= 5.6.0, PHP 7

Function Description: The session_reset() function will reinitialize all session variables and move the session pointer to the beginning of the session array.

Syntax: session_reset()

Example:

 // 开启会话session_start(); // 设置会话变量$_SESSION['username'] = 'John'; $_SESSION['age'] = 25; // 输出会话变量echo $_SESSION['username']; // 输出:John echo $_SESSION['age']; // 输出:25 // 重置会话变量session_reset(); // 输出会话变量echo $_SESSION['username']; // 输出:John echo $_SESSION['age']; // 输出:25

illustrate:

  1. First, you need to use the session_start() function to start the session.
  2. Use the $_SESSION hyperglobal variable to set the session variable.
  3. Calling session_reset() function moves the session pointer to the beginning of the session array and reinitializes the session variable.
  4. After calling session_reset() , the session variable is still accessible.
  5. Note that the session_reset() function will only reset the current session and will not affect other sessions.
  6. If the session is not enabled or destroyed, calling session_reset() function will throw a warning.

Additional Notes:

  • The session_reset() function is suitable for situations where session variables need to be reinitialized and session pointer moved to the beginning. For example, this function can be used when you need to re-traverse the session array.
  • If you just need to destroy the session variables and reinitialize the session pointer, you can use session_unset() function.
  • If you need to destroy the entire session and release the session file lock, you can use session_destroy() function.
Similar Functions
Popular Articles