[ create a new paste ] login | about

Link: http://codepad.org/Z3HqIaFh    [ raw code | output | fork ]

zuul - PHP, pasted on Jun 14:
<?php
function killsession()
{
  // start the session, if started before, comment
  session_start();

  // Unset all of the session variables. 
  $_SESSION = array();

  // destroy the session, and not just the session data!
  if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
  }

  // destroy the session.
  session_destroy();

  // direct user
  header("Location: index.php");
}



/* ------------------------------ *

             TESTING

 * ------------------------------ */
session_start();

$_SESSION['userid']=25;
$_SESSION['userName']='Super BuBu';

print_r($_SESSION);

killsession();

print_r($_SESSION);
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Warning: session_start(): open(/tmp/sess_7839f073acb49da3dd64c6bcdcbba1bb, O_RDWR) failed: No such file or directory (2) on line 33

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /t.php:33) on line 33

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /t.php:33) on line 33
Array
(
    [userid] => 25
    [userName] => Super BuBu
)

Warning: Cannot modify header information - headers already sent by (output started at /t.php:33) on line 16

Warning: Cannot modify header information - headers already sent by (output started at /t.php:33) on line 23
Array
(
)


Create a new paste based on this one


Comments: