我制作了一個叫作 blog_session.php , 把它放在blog 的根目錄中 再用外部的index.php
include 這個php 檔.
假設index.php 是用http_authentication 形式登入系統中,
然後用session 存入了登入的 username 及 password.
到執行blog_session.php 時傳回session
<?php
if (!defined( "PLOG_CLASS_PATH" )) {
define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
}
include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/net/http/session/sessioninfo.class.php" );
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
include_once( PLOG_CLASS_PATH."class/misc/version.class.php" );
include_once( PLOG_CLASS_PATH."class/net/http/session/sessionmanager.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
//取得http auth user and Password
$userName = $_SESSION["SNam"];
$userPassword = $_SESSION["Spw"];
/*SessionManager::init();
$session = HttpVars::getSession();
$sessionInfo = $session["SessionInfo"];
$userInfo = $sessionInfo->getValue( "userInfo" );
echo $userInfo->getId();
echo $userInfo->getUsername();*/
// 產生一個新的 user 物件
$users = new Users();
// 取得 userInfo 物件 (透過正確的 username 與 password)
//$userInfo = $users->getUserInfoFromUsername($userName);
$userInfo = $users->getUserInfo( $userName, $userPassword );
// 取得使用者的 blog list
$userBlogs = $users->getUsersBlogs( $userInfo->getId(), BLOG_STATUS_ACTIVE );
// 用第一個 blog 來當作 blogID,並取得這個 blog ID 的 blogInfo
$blogInfo = end( $userBlogs );
// 取得 session
$session = HttpVars::getSession();
$sessionInfo = $session["SessionInfo"];
// 並且把資料寫入session
$sessionInfo->setValue( "userInfo", $userInfo );
$sessionInfo->setValue( "blogInfo", $blogInfo );
$session["SessionInfo"] = $sessionInfo;
HttpVars::setSession( $session );
?>
結果是
Fatal error: Call to undefined method Users::getUserInfo() in c:\AppServ\www\blog\blog_session.php on line 34