插件66:打開回話

<?php // Plug-in 66: Open 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.";
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\n";
}

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_OpenSession();
   //    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);
}

?>

發佈了160 篇原創文章 · 獲贊 12 · 訪問量 113萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章