Imitate the Hanshunping teacher to do the web chat system, the great God help see what the problem
This post was last edited by Alakey on 2014-01-18 22:52:59
chatroom.php******
Accept the user name passed by open
$username =$_get[' username '];
$username =trim ($username);
Session_Start ();
$loginuser =$_session[' Loginuser '];
?>
Web chat room (
being and
chatting)
getmessagecontroller.php********
Require_once ' MessageService.class.php ';
Header ("Content-type:text/xml;charset=utf-8");
Header ("Cache-control:no-cache"):
$getter =$_post[' getter '];
$sender =$_post[' sender '];
$messageService =new Messageservice ();
$messageList = $messageService->getmessage ($getter, $sender);
Echo $messageList;
?>
messageservice.class.php********
Require_once ' SqlHelper.class.php ';
Class messageservice{
function AddMessage ($sender, $getter, $con) {
$sql = "INSERT INTO messages (Sender,getter,content,sendtime) VALUES (' $sender ', ' $getter ', ' $con ', Now ())";
$sqlHelper =new sqlHelper ();
Return $sqlHelper->execute_dml ($sql);
}
function GetMessage ($getter, $sender) {
$sql = "SELECT * from messages where getter= ' $getter ' and sender= ' $sender ' and isget=0 ';
$sqlHelper =new sqlHelper ();
$array = $sqlHelper->execute_dql2 ($sql);
$messageInfo = "
";
for ($i =0; $i<>
$row = $array [$i];
$messageInfo. = "
{$row [' id ']}
{
$row [' Sender ']}
{$row [' getter ']}
{$row [' Conte NT ']}
{$row [' Sendtime ']}
";
}
$messageInfo. = "
";
$sqlHelper->close_connect ();
return $messageInfo;
}
}
?>
The great God help to see where the problem is?
------to solve the idea----------------------
Didn't look carefully. Single sentence: Session_Start ();
Because there is an HTML tag in front of the output, there will definitely be "headers already sent" error, right?
You didn't tell me what was wrong with you.
------to solve the idea----------------------
It's important to write robust code.
....
if (myxmlhttprequest.status==200) {
var mesres=myxmlhttprequest.responsexml;
if (Mesres.xml = = ") {//If it is not an XML object
alert (myxmlhttprequest.responsetext);//See what's returned
Return
}
....
------to solve the idea----------------------
This estimate is also a appearance bar, the performance is relatively poor.
Chat rooms, using websockeet or comet,
Second, you don't have to use a database, Redis or file storage to
------to solve the idea----------------------
Header ("Cache-control:no-cache"):
This kind of mistake, the hint should be obvious.