How to destroy a session in PHP

1 Answer

0 votes
<?php
/*
bool session_start ([ array $options = [] ] )

// With session we store information in variables that used across multiple pages
// The variables is not stored on the computer


void session_unset ( void )

bool session_destroy ( void )

*/
  
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php

$_SESSION["user_name"] = "ron";
$_SESSION["country"] = "usa";
echo $_SESSION["user_name"] . " - " . $_SESSION["country"];

// remove all session variables
session_unset();

// destroy the session
session_destroy(); 

echo $_SESSION["user_name"] . " - " . $_SESSION["country"];

?>
</body>
</html>
<?php
      
/*
run:
  
ron - usa
Notice: Undefined index: user_name in C:\xampp\htdocs\workingframe.com\test.php on line 28

Notice: Undefined index: country in C:\xampp\htdocs\workingframe.com\test.php on line 28
- 

*/

?>

 



answered Dec 24, 2015 by avibootz

Related questions

1 answer 160 views
160 views asked Oct 24, 2015 by avibootz
1 answer 184 views
184 views asked Nov 29, 2020 by avibootz
1 answer 198 views
198 views asked Nov 29, 2020 by avibootz
1 answer 200 views
1 answer 181 views
181 views asked Nov 29, 2020 by avibootz
1 answer 161 views
...