1
我有一個顯示聊天框的主文檔。我想要的是當有人發佈新消息時,聊天室會在每個人的屏幕上刷新。PHP檢查/重新刷新功能
我已經嘗試過很多方法,包括睡眠定時器和調用睡眠並被調用的新函數,但是這隻會產生無數的相同或不同的數據,使得表單無法使用直到出現錯誤。
這是我的代碼。
<?php
// set error reporting level
if (version_compare(phpversion(), "5.3.0", ">=") == 1)
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
error_reporting(E_ALL & ~E_NOTICE);
require_once('inc/login.inc.php');
require_once('inc/chat.inc.php');
// initialization of login system and generation code
$oSimpleLoginSystem = new SimpleLoginSystem();
$oSimpleChat = new SimpleChat();
// draw login box
echo $oSimpleLoginSystem->getLoginBox();
// draw chat application
$sChatResult = '<font color="0x99000">
<a href="Register_form.html">New Account</a><br>
login to send a message<br>
or register for a new account</font>';
if ($_COOKIE['member_name'] && $_COOKIE['member_pass'])
{
if ($oSimpleLoginSystem->check_login($_COOKIE['member_name'], $_COOKIE['member_pass'])) {
$sChatResult = "";
if($oSimpleLoginSystem->check_privledges($_COOKIE['member_name']) >= 2)
{
$sChatResult .= "<br>privledge check Working<br>";
}
$sChatResult .= "<form action=$_SERVER[PHP_SELF] method='post'>
<input type='hidden' name='foo' value='<?= $foo ?>' />
<input type='submit' name='submit' value='Refresh Messages' />
</form>";
$sChatResult .= $oSimpleChat->acceptMessages();
$sChatResult .= "<br><br>";
$sChatResult .= $oSimpleChat->getMessages();
}
}
echo $sChatResult;
?>