我不能給你一個答案,如何與正在使用的論壇軟件實現這一點。我已經檢查過這個網站,他們有mods和插件的論壇,所以你可能會問,如果這是一個插件(除非有人知道這個插件)。
要找出當前登錄到你的網站,你可以做沿此線的東西所有用戶的IP地址(目前我們定義登錄爲「有一個會議」):
// put in your bootstrap after you defined getRealIpAddr()
if(session_id() === '') {
session_start();
}
$_SESSION['ip'] = getRealIpAddr();
然後在你的lib中添加一個SessionReader類,例如
class SessionReader
{
// serializes session data without destroying your own session
public function decode($filecontent){
// see http://de.php.net/manual/de/function.session-decode.php#69111
}
// just reads in the contents of a session file
public function readSessionData($file)
{
return file_get_contents(realpath("$session_save_path/$file"));
}
// returns all filenames in save path starting with 'sess'
public function getSessionFiles()
{
$path = realpath(session_save_path());
return glob($path . '/sess*');
}
// uses the above methods to build an array of all decoded sessions
public function getEveryonesSessionData()
{
$contents = array_filter($this->getSessionFiles(),
array($this, "readSessionData"));
return array_filter($contents, array($this, "decode"));
}
}
要使用它,做
$sessionReader = new SessionReader;
foreach($sessionReader->getEveryonesSessionData() as $session) {
echo $session['IP'];
}
免責聲明:這只是一個概念證明又名醜陋的黑客。我不希望這個工作沒有進行調整。所以你不應該。但你應該能夠從這裏完成。
SessionReader應該能夠讀取PHP.ini或應用程序中其他位置指定的session_save_path中的所有會話文件。假設是,會話文件以sess開頭並存儲在文件系統中。當調用getEveryonesSessionData()時,該類將查找,讀取,解碼並返回數組中的所有會話文件,以便您可以逐個訪問它們。
爲了使您的論壇軟件能夠正常運行,您必須瞭解他們如何定義當前登錄的用戶以及他們是否以及如何使用會話。
感謝您的回答,我想擁有一個列出在線用戶IP的頁面,非常簡單。 – Alireza 2010-01-06 20:13:10