Imitate the Hanshunping teacher to do the web chat system, the great God help to see what the problem

Source: Internet
Author: User
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.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.