shaher11
shaher11

Reputation: 140

How can I destroy (clear) a session php?

if (isset($_POST['clear'])) {
      session_unset($_SESSION['dataRow']);
      session_unset($_SESSION['dataColumn']);
      session_destroy();
      echo ' Data has been deleted. ';
}

enter image description here

Upvotes: 1

Views: 794

Answers (1)

Mohammad_Hosseini
Mohammad_Hosseini

Reputation: 2599

Unset will destroy a particular session variable while session_destroy() will destroy all the session data for that user.

It depends on your application how to use it, just keep this in mind:

unset($_SESSION['name']); // will delete just the name data

session_destroy(); // will delete ALL data associated with that user.

Upvotes: 5

Related Questions