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;
?>