歡迎光臨, 訪客. 請先 登入註冊一個帳號.
五月 02, 2024, 12:27:29 下午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  支援  |  使用與操作  |  請問如何使用外部http 登入的username 及password 直接登入plog 的後台? « 上篇主題 下篇主題 »
頁: [1]
作者 主題: 請問如何使用外部http 登入的username 及password 直接登入plog 的後台?  (閱讀 11472 次)
pcm
新手見習
*
文章: 12


檢視個人資料
« 於: 十一月 09, 2006, 12:22:52 下午 »

我現在的系統是使用http_authenticaion 的方法登入

登入後login username 及password 亦已紀錄在http_auth_user 及 http_auth_pw兩個變數中,

plog user 都直接

我search 過論壇, 看過了關於session 的post , 但還是有點不明白,

開始有點製作概念, 有以下幾點:

概念 1. 利用外部的php 把得回來的username 及password 用$_SESSION["SessionInfo"]->getValue 的方法
直接寫入到plog 的session, 使用戶假設在summary.php 按" 發表新文章"連結時可以直接進入後台.

但還是有個問題, 就是那個外部的php 是否一定要include 所有想關的class 才可運作?

那個php 可以是否一定要放入plog 的資料夾中才可以正常使用那些class?

用這堆code 能否把http_auth  得回來的資料寫入session.?


// 產生一個新的 user 物件
$users = new Users();
// 取得 userInfo 物件 (透過正確的 username 與 password)
$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 );


概念 2. 先從外部把http_auth 得回來的資料寫入session, 在現有plog 的php中(例如summary.php 或是其他地方) 加入可以傳回plog外部session 的code
把header template 中修改一下, 用兩個全域變數代表session 的username 及password.( 例如 {$snam} 及{$spw} )
然後使用戶假設在summary.php 按" 發表新文章"連結時可以用post 方式(即admin.php?op=Login&userName={$snam}&userPassword={$spw})直接進入後台.

但是我不知道要怎麼做才能在plog 裡面把這個外部建立的session 能夠在plog 的頁面中使用到.



請各位指教




已記錄
pcm
新手見習
*
文章: 12


檢視個人資料
« 回覆文章 #1 於: 十一月 09, 2006, 04:11:13 下午 »

我制作了一個叫作 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
已記錄
pcm
新手見習
*
文章: 12


檢視個人資料
« 回覆文章 #2 於: 十一月 10, 2006, 10:55:17 上午 »

今天找到了一篇前者在這裡問過的方法

http://forum.lifetype.org.tw/index.php?topic=1347.0

我也跟著修改了一下..

結果是..
Fatal error: Call to a member function error() on a non-object in c:\AppServ\www\blog\class\cache\Cache_Lite\Lite.php on line 724


還差了什麼呢?? 嚎啕大哭
已記錄
頁: [1]
LifeType 中文開發論壇  |  支援  |  使用與操作  |  請問如何使用外部http 登入的username 及password 直接登入plog 的後台? « 上篇主題 下篇主題 »
    前往: