<?php // Plug-in 67: Close Session
/*
*插件说明:
*插件关闭已经打开的session的PHP会话,并销毁与这个会话有关的任何参数。不需要参数。
*/
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$result = PIPHP_OpenSession();
if (!$result[0]) echo "Could not open session.<br />";
else
{
list($handle, $pass, $name, $email) = $result[1];
echo "Retrieving session variables:<pre>";
echo "Handle: $handle\n";
echo "Pass: $pass\n";
echo "Name: $name\n";
echo "Email: $email</pre>";
}
$result = PIPHP_CloseSession();
if ($result == TRUE) echo "Session closed.";
else echo "Session close failed.";
function PIPHP_CloseSession()
{
// Plug-in 67: Close Session
//
// This plug-in ends a previously started session.
// It does not take any arguments and returns TRUE
// on success, otherwise FALSE.
$_SESSION = array();
if (session_id() != "" ||
isset($_COOKIE[session_name()]))
setcookie(session_name(), '', time() - 2592000, '/');
return @session_destroy();
}
// The plug-in below is included here to ensure it is available
// to the main plug-in which relies on it
function PIPHP_OpenSession()
{
// Plug-in 66: Open Session
//
// This plug-in returns the four user variables.
// It doesn't take any parameters. On success it
// returns a two-element array, the first of which
// has the value FALSE, and the second is an array
// of values. On failure (if the session variables
// don't exists, for example), it returns a single
// element array with the value FALSE. An easy way
// to read the return values is with a list()
// statement, like this:
//
// $result = PIPHP_ReadSession();
// list($h, $p, $n, $e) = $result[1];
if (!session_start()) return array(FALSE);
if (!isset($_SESSION['handle'])) return array(FALSE);
$vars = array();
$vars[] = $_SESSION['handle'];
$vars[] = $_SESSION['pass'];
$vars[] = $_SESSION['name'];
$vars[] = $_SESSION['email'];
return array(TRUE, $vars);
}
?>