Author Topic: Cần giúp chương trình CHAT dùng php  (Read 1725 times)

xecvantec

  • PHP Starter
  • *
  • Posts: 4
    • View Profile
    • Email
Cần giúp chương trình CHAT dùng php
« on: September 28, 2011, 03:07:25 PM »
Mình muốn tạo 1 chuong trình chat nhỏ

Có code:
[syntax=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php

?>
<input type="hidden" name="des" id="des">

</input>
      <?php     
     $str=" ";
        if (isset ($_POST["txtNi1"]))
      {
            $text1 =$_POST["txtNi1"];
         echo ("<br/>");
        $str.=$text1."\\";
        echo $str;
      }
      if (isset ($_POST["txtNi2"]))
      {
            $text2 =$_POST["txtNi2"];
         echo ("<br/>");
        $str.=$text2."\\";
        echo $str;
      }
   
       


?>

<body>

<form name="form1" method="post" action="test4.php">
<table>
   <tr>
       <td>Nick 01: </td>
        <td><input name="txtNi1" type="text" id="txtNi1"/></td>
    </tr>
    <tr>
       <td colspan="2" align="center" > <input name="Send1" type="submit" value="Send" /></td>
    </tr>
</table>
</form>
<form name="form2" method="post" action="test4.php">
<table>
    <tr>
       <td>Nick 02</td>
       <td><input name="txtNi2" type="text" id="txtNi2"/></td>
    </tr>
    <tr>
       <td colspan="2" align="center"> <input name="Send2" type="submit" value="Send" /></td>
    </tr>
</table>
</form>
    <div id="place" > </div>
    <td><input type="hidden" name="" value="" id="textHid"/></td>
    <input type="hidden" name="textHid" value="" id="textHid"/></span>
</body>
</html>
[/syntax]

Nhưng nó chỉ lấy nội dung chat mới, mất nội dung cũ.
Vậy sửa lỗi như thế nào?

tut4ever

  • PHP Starter
  • *
  • Posts: 3
  • mibvn.info
    • View Profile
    • diễn đàn mibvn
    • Email
Re: Cần giúp chương trình CHAT dùng php
« Reply #1 on: September 29, 2011, 04:06:39 PM »
Có 2 hướng:
cổ điển ko chơi ajax thì ... bác phải lưu nó lên 1 file nào đó dạng xml hoặc txt.
"hiện đại" tí thì chơi ajax đỡ phải load trang Nhưng vẫn cần dùng file để lưu nội dung cho người kia.
Chứ file html xử lí thể kia thì chỉ 1 máy tự 'xướng' đc thôi.
Cơ bản các bước như sau:
send request tới file php bằng ajax,
file php sẽ xử lí(lưu lời chat vào file text và đọc lại nội dung trong file text ấy) và trả về nội dung cho người chat.
Cơ bản là thế thôi.