Parsa Mir Hassannia
Parsa Mir Hassannia

Reputation: 351

session_unset VS session_reset

I want to know what is the difference between session_unset and session_reset.

Both of them clears $_SESSION data, so what is their difference, and can you give me an example for each one?

Upvotes: 0

Views: 252

Answers (1)

Ahmad
Ahmad

Reputation: 5760

Actually you are wrong. session_reset is for rolling back changes that has made to the session.

See this example, from PHP documentation (a little different):

<?php
    session_start();
    $_SESSION["A"] = "Some Value";
?>

Execute this code first and then, execute this:

<?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().

Upvotes: 3

Related Questions