我正在嘗試編寫一個系統,顯示誰登錄到我的網站。「誰登錄」不工作
我已經嘗試過這麼多的東西,而且我覺得我正在用這個東西 - 但它不工作。我需要幫助,試圖找到我出錯的地方。
這裏是我的顯示代碼(我知道我不應該用表格的格式,但我用它來測試):
<?
$loggedInUsers2 = "SELECT * FROM techs WHERE Level='0' AND LastTimeSeen>DATE_SUB(NOW(), INTERVAL 5 MINUTE)";
$loggedInUsers3 = "SELECT * FROM techs WHERE Level>'0' AND LastTimeSeen>DATE_SUB(NOW(), INTERVAL 5 MINUTE)";
?>
<div class="col-sm-4">
<div class="thumbnail">
<center><h4 style="height:35px;">Users Online</h4></center>
<div class="modal-body" style="min-height:498px;">
<table>
<tr><td>
<?
mysqli_query($con, $loggedInUsers2) or die("Error " . mysqli_error($con));
while($row2 = mysqli_fetch_array($loggedInUsers2)) { //if level less than 1
echo $row2['Name']."<br/>";
}
?>
</td><td>
<?
mysqli_query($con, $loggedInUsers3) or die("Error " . mysqli_error($con));
while($row3 = mysqli_fetch_array($loggedInUsers3)) { //if level more than 1
echo $row3['Name']."<br/>";
}
?>
</td></tr>
</table>
</div>
</div>
</div>
這是我保存到數據庫:
$userId = $_SESSION['UserId'];
$loggedInUsers1 = "UPDATE techs SET LastTimeSeen=NOW() WHERE UniqueID='$userId'";
mysqli_query($con, $loggedInUsers1) or die("Error " . mysqli_error($con));
這輸出到我的數據庫(在LastTimeSeen字段)到類似2015-12-21 08:35:43
(更新每隔幾秒鐘通過jquery重新加載頁面的頁腳)
基本上,只有沒有從第一頁輸出到表格中。
編輯:
有人建議使用的登錄按鈕來設置用戶激活,註銷按鈕設置無效 - 這是我給的迴應:
"The problem with that is people won't use the logout button. They will just close the browser. I want this to keep track of only users that are online. The footer updates the time in the database, every couple of seconds, and then the table is listed on a part of the page that reloads every few seconds aswell, so they are both always up to date. It should only list people that have been on a page in the past 5 minutes."
是的,因爲我說這是我認爲問題是 –