我也在关注,不过用php好象做不到。

解决方案 »

  1.   

    要用php和javascript结合才能做的出来,具体的你可以找找 javascript的书
      

  2.   

    我知道要用到js的document.write()。但是具体怎么写啊?那数据库也是要刷新的啊。不过我不知道怎么写啊???
    谁知道啊,怎么刷新啊,我想不出来了,谁能说出核心的写法啊,尤其是怎么刷新啊
      

  3.   

    http://justflycn.51.net/showupload.php?serial=20&&type=文档收集
      

  4.   

    可用的聊天室都是基于socket的。
      

  5.   

    我找到了一段代码,可是我有的地方没看明白啊,谁帮我看看啊??在body里的<meta>能工作吗?
    代码:
    <html><SCRIPT LANGUAGE="JavaScript1.1">
    <!--
    var autoScrollOn = 1;
    var scrollOnFunction;
    var scrollOffFunction;
    function scrollit(){if(!parent.d.document.inputform.as.checked){autoScrollOn=0;return true;}else {autoScrollOn=1;StartUp();return true;}}
    function scrollWindow( ){if ( autoScrollOn == 1 ){this.scroll(0, 65000);setTimeout('scrollWindow()',200);}}
    function scrollOn( ){autoScrollOn = 1;scrollWindow( );}
    function scrollOff( ){autoScrollOn = 0;}
    function StartUp( ){this.onblur  = scrollOnFunction;this.onfocus = scrollOffFunction;scrollWindow( );}
    scrollOnFunction = new Function('scrollOn( )')
    scrollOffFunction = new Function('scrollOff( )')
    StartUp();
    //--></script>
    <style type="text/css">
    <!--
    td {   font-size: 12px}
    body {  font-size: 18px}
    .p14 {  font-size: 13px}
    select {   font-size: 12px}
    A {color: #000000;font-size: 12px}
    A:hover {BACKGROUND:#66FF00;font-style:normal;text-decoration:none;font-size:11pt;color:red}
    A:link {  font-size: 11pt; color: #0066FF; text-decoration: none}
    A:visited {text-decoration: none }hr {color: #0370C0}
    li {  list-style-type: square; line-height: 15pt}
    .line01 {  line-height: 18px;letter-spacing: 2}
    -->
    </style>
    <script language="javascript">
    gepath=new Array(30);
    ge=new Array(30);
    ge[1]="千千阙歌"; gepath[1]="mid/22.mid";
    ge[2]="爱火烧不尽";gepath[2]="mid/lovefire.mid";
    ge[3]="泰坦尼克号";gepath[3]="mid/titanic.mid";
    ge[4]="风中奇缘";gepath[4]="mid/wind.mid";
    ge[5]="太傻";gepath[5]="mid/taisha.mid";
    ge[6]="不是我不小心";gepath[6]="mid/bushiwobxx.mid";
    ge[7]="风雨无阻";gepath[7]="mid/fywz.mid";
    ge[8]="大地";gepath[8]="mid/dadi.mid";
    ge[9]="光辉岁月";gepath[9]="mid/guanghuisy.mid";
    ge[10]="孤枕难眠";gepath[10]="mid/gznm.mid";
    ge[11]="哭砂";gepath[11]="mid/kusha.mid";
    ge[12]="爱那么重";gepath[12]="mid/ainamez.mid";
    ge[13]="真的爱你";gepath[13]="mid/zdan.mid";
    ge[14]="梁祝";gepath[14]="mid/liangzhu.mid";
    ge[15]="晚秋";gepath[15]="mid/qanqiu.mid";
    ge[16]="千纸鹤";gepath[16]="mid/qzh.mid";
    ge[17]="相思风雨中";gepath[17]="mid/misswind.mid";
    ge[18]="深爱着你";gepath[18]="mid/63.mid";
    ge[19]="听   海";gepath[19]="mid/50.mid";
    ge[20]="短   发";gepath[20]="mid/47.mid";
    ge[21]="鸭   子";gepath[21]="mid/37.mid";
    ge[22]="真 永 远";gepath[22]="mid/97.mid";
    ge[23]="用心良苦";gepath[23]="mid/44.mid";
    ge[24]="心 太 软";gepath[24]="mid/99.mid";
    ge[25]="变心的翅膀";gepath[25]="mid/54.mid";
    ge[26]="等你一万年";gepath[26]="mid/51.mid";
    ge[27]="阿信的故事";gepath[27]="mid/axin.mid";
    ge[28]="生 日 歌";gepath[28]="mid/bri.mid";
    ge[29]="我 愿 意";gepath[29]="mid/yuan.mid";
    function sended(n,who){
      if (window.confirm("~~ "+ who + "点了一首音乐 [ "+ge[n]+" ] 给你 !打算收听吗?~~ \n\n收听请按'确定',否则按'取消'返回聊天室,谢谢!")) {
      p=window.open('','g','width=300,height=50');
      p.document.write("<html><title>罗湖教育聊天室点歌台</title><bgsound loop='-1' src='"+gepath[n]+"'</bgsound><body>这是 "+who+" 为你点的 "+ge[n]+"<br>请稍等,正在下载播放......<p><a href='javascript:self.close()'>关闭窗口</a></body></html>");
    }
      }
    function talkto(n){
    parent.input.document.inputform.who.value=n;
    parent.input.document.inputform.mess.focus();
    }
    function send(who,towho,say,face,color,time,biaoqing){
    parent.bottom.scroll(0, 65000);
    parent.bottom.document.write("<html><body bgcolor='#F8F9EE'></html>");
    parent.bottom.document.write("<html><img src='"+biaoqing+"' border=0 width=15></html>");
    if(face==""){
    parent.bottom.document.write("<html><body><font size=3 color=#ff0000><a href=javascript:parent.talkto('"+who+"') target=input><ACRONYM TITLE='选取 "+who+" 为谈话对象'>"+who+" </ACRONYM></a></font><font size=3>对</font><font color='#FF0000' size=3><b>●● "+towho+" </b></font><font size=3>说</font><font size=3 color="+color+"> " +say+ " </font><font color=#ff0000 size=-1>&nbsp;&nbsp;("+time+")</font></body></html>");
    }else{
    parent.bottom.document.write("<html><body><font size=3 color=#ff0000><a href=javascript:parent.talkto('"+who+"') target=input><ACRONYM TITLE='选取 "+who+" 为谈话对象'>"+who+" </ACRONYM></a></font><font size=3>对</font><font color='#FF0000' size=3><b>●● "+towho+" </b></font><font size=3>"+face+"</font><font size=3 color="+color+"> " +say+ " </font><font color=#ff0000  size=-1>&nbsp;&nbsp;("+time+")</font></body></html>");
    }
    parent.bottom.document.write("<br>");
    parent.bottom.scroll(0, 65000);
       }function send1(who,towho,say,face,color,time,biaoqing){
    parent.bottom.scroll(0, 65000);
    parent.bottom.document.write("<html><body bgcolor='#F8F9EE'></html>");
    parent.bottom.document.write("<html><img src='"+biaoqing+"' border=0 width=15></html>");
    if(face==""){
    parent.bottom.document.write("<html><body>"+who+"<font size=3>对</font><font size=3 color=#ff0000><a href=javascript:parent.talkto('"+towho+"') target=input><ACRONYM TITLE='选取 "+towho+" 为谈话对象'>"+towho+" </ACRONYM></a></font><font size=3>说</font><font size=3 color="+color+"> " +say+ " </font><font color=#ff0000 size=-1>&nbsp;&nbsp;("+time+")</font></body></html>");
    }else{
    parent.bottom.document.write("<html><body>"+who+"<font size=3>对</font><font size=3 color=#ff0000><a href=javascript:parent.talkto('"+towho+"') target=input><ACRONYM TITLE='选取 "+towho+" 为谈话对象'>"+towho+" </ACRONYM></a></font><font size=3>"+face+"</font><font size=3 color="+color+"> " +say+ " </font><font color=#ff0000  size=-1>&nbsp;&nbsp;("+time+")</font></body></html>");
    }
    parent.bottom.document.write("<br>");
    parent.bottom.scroll(0, 65000);
    }function send2(who,towho,time,pic,biaoqing){
    parent.bottom.scroll(0, 65000);
    parent.bottom.document.write("<html><body bgcolor='#F8F9EE'></html>");
    parent.bottom.document.write("<html><img src='"+biaoqing+"' border=0 width=15></html>");
    parent.bottom.document.write("<html><body>"+who+"<font size=3 color=#ff0000>送给"+"<a href=javascript:parent.talkto('"+towho+"') target=input><ACRONYM TITLE='选取 "+towho+" 为谈话对象'>"+towho+"</a>一件珍贵的</font><img src='gift/"+pic+"' border=0><font color=#ff0000 size=-1>&nbsp;&nbsp;("+time+")</font></body></html>");
    parent.bottom.document.write("<br>");
    parent.bottom.scroll(0, 65000);
    }
    </script><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"><body bgcolor="#deebff">
    <body topmargin="0">
    <?php$result=mysql_query("select * from hbw  where room='$room'");
    $rn=mysql_num_rows($result)-1;print "欢迎光临小毛驴聊天室<br>";
    $delaytime=0;
    $delaytime1=0;
    //循环
    while(1)
    {
    $t = date("H:i:s");
    //延迟1秒钟sleep(1);
    $delaytime=$delaytime+1;
    //时间标记增加
    $delaytime1=$delaytime1+1;if($delaytime>60){
    $query=mysql_query("insert into hbw values('j','','','','','*','','','','$room','')");
    $delaytime=0;
    $ttttt=1;
    }
    //如果时间标记快到允许的脚本运行时间则退出循环
    if($delaytime1>2500){
    break;
    }$result=mysql_query("select * from hbw where room='$room'");
    $rn1=mysql_num_rows($result);//如果有新的发言则退出循环
    if($rn!=$rn1 ) {$result=mysql_query("select * from hbw where room='$room'");
    $rn1=mysql_num_rows($result);
    $al=$rn1-$rn;
    $query=mysql_query("select * from hbw where room=$room order by id desc limit $al");
    while($lin=mysql_fetch_array($query)){
    $biaoqing="./biaoqing/".$lin[10].".gif";  $qu=mysql_query("select count(*) from friendhi where nameh='$name' and name='$lin[2]'");
      $forbiden=mysql_result($qu,0);
      if ($forbiden>0){continue;}
      if($name==$lin[1]){
      $to="<font color='#FF0000' size=3><b>●●<u>".$lin[1]."</u></b></font>";
          }
      else{
        $to="<a href=\"javascript:parent.talkto('$lin[1]')\" target='input'><ACRONYM TITLE='选取 ".$lin[1]." 为谈话对象'>"."<font  size=3>".$lin[1]."</font>"."</ACRONYM></a>";
         }
         if($name==$lin[2]){
         $wo="<font color='#800000' size=2>$lin[2] [自己]</font>";
        }else{
      $wo="<a href=\"javascript:parent.talkto('$lin[2]')\" target='input'><ACRONYM TITLE='选取 ".$lin[2]." 为谈话对象'><font size=3>".$lin[2]."</font></ACRONYM></a>";
        }
    $etom="对".$to.$lin[3];
       $temp=substr($lin[5],0,2);
       if ($temp=="//"){
       $say=addslashes($lin[5]);
       $q=mysql_query("select * from emote where command=\"$say\"");
       $rowa=mysql_fetch_row($q);
       $row=$rowa[1];
       if ($row) { $lin[5]=str_replace("对象",$to,$row);
                   $etom="";}
       }   $temp1=substr($lin[5],0,3);
       if ($temp1=="/-/"){
       $gift=substr($lin[5],3,strlen($lin[5])-3);
       $biaoji3="送给".$to."一件珍贵的<img src=gift/".$gift.">";
       $etom="";
         }else{$biaoji3=$lin[5];}if($lin[0]=="j" and $ttttt==1){
     echo "<font size=-2>$biaoji3</font>";
    $ttttt=0;
     }if(($lin[0]=="n" or $lin[0]=="s") and $lin[1]==$name  and ($temp!="//" and $temp1!="/-/")){
     echo "<script>send('$lin[2]','$lin[1]','$lin[5]','$lin[3]','$lin[4]','$lin[7]','$biaoqing');</script>";
     }
    if(($lin[0]=="n" or $lin[0]=="s") and $lin[2]==$name  and ($temp!="//" and $temp1!="/-/")){
     echo "<script>send1('$lin[2]','$lin[1]','$lin[5]','$lin[3]','$lin[4]','$lin[7]','$biaoqing');</script>";
     }
    if(($lin[0]=="n") and ($lin[1]==$name or $lin[2]==$name) and $temp1=="/-/"){
     echo "<script>send2('$lin[2]','$lin[1]','$lin[7]','$gift','$biaoqing');</script>";
    }   if ($lin[0]=="i"){
         $ttt=1;
         echo "<font color=red size=2>【系统提示】</font>$wo<font color=#008000 size=2>进入聊天室!</font>  <font color='#808080' size=-1>($lin[7])</font><br>";}
       elseif ($lin[0]=="o"){
        $ttt=1;
         echo "<font color=#aaaaaa size=2>【系统提示】<b>$lin[2]</b>离开聊天室!  <font color='#808080' size=-1>($lin[7])</font></font><br>";}
      /*
       elseif ($lin[0]=="q"){
       $ttt=1;
         echo "<font color=#aaaaaa size=2>【系统提示】$wo 清除掉聊天记录!  <font color='#808080' size=-1>($lin[7])</font></font><br>";}*/
       elseif ($lin[0]=="t"){
         if ($lin[2]==$name)
                {    mysql_query("delete from online where name='$name' and room=$room");
                        echo "<script>alert('因为你说话不文明,被管理员踢出聊天室')</script>";            echo  "<script src='f3.js'></script>";            }
         $ttt=1;
         echo "<font color=#aaaaaa size=2>【系统提示】<b>$lin[2]</b>因不遵守聊天规则,被 $to 踢出聊天室!  <font color='#808080' size=-1>($lin[7])</font></font><br>";
         }
       elseif ($lin[0]=="g" || $lin[0]=="k"){
         if ($lin[1]==$name && $lin[0]=="g")
                {echo "<script>sended($lin[6],'$lin[2]');</script>";
                 mysql_query("update hbw set type='k' where id='$lin[8]' and room=$room");}
         $ttt=1;
         echo "∮$wo 点了一首 $lin[5] 给$to 听......<br>";
         }
       elseif ($lin[0]=='c'){
          $ttt=1;
         echo "<font color=#aaaaaa size=2>【系统提示】<font size=-1 color='#008080'>$lin[2]</font>操作超时了,重重地摔了下去!  <font color='#808080' size=-1>($lin[7])</font></font><br>";
         }
       elseif ($lin[0]==n){
         $ttt=1;
         if ($temp1=="/-/"){
         echo "<img src=$biaoqing border=0 width=17>$wo$etom<font color=$lin[4]>$biaoji3 <font face=wingdings>$lin[6]</font> <font color='#808080' size=-1>($lin[7])</font></font><br>";
        }else{
         echo "<img src=$biaoqing border=0 width=17>$wo$etom<font color=$lin[4]>$lin[5]  <font face=wingdings>$lin[6]</font> <font color='#808080' size=-1>($lin[7])</font></font><br>";
         }}
       elseif ($lin[1]==$name || $lin[2]==$name){
        $ttt=1;
           echo "☆☆<img src=$biaoqing border=0 width=17>$wo$etom<font color=$lin[4]>$lin[5]  <font face=wingdings>$lin[6]</font> <font color='#808080' size=-1>($lin[7])</font></font><br>";}
         }flush();
    mysql_free_result($result);       #释放数据库结果占用的内存 ,不然数据库会崩溃
    $rn=$rn1;
    if($ttt==1){$delaytime=0;}
    $ttt=0;
    $lay=1;
    }
    }
    ?><p>&nbsp;</p><meta http-equiv="Refresh" content="1; url=./view.php?name=<? echo $name; ?>&amp;room=<? echo $room; ?>&amp;rn=<? echo $rn1; ?>&amp;alzhan=2%3E"></body>
    </html>
     
      

  6.   

    to danfeng(丹枫) 
    本来用php写聊天室已经是够慢的了,要是再加上数据库的话,速度就更下去了
    另外还有定时扫描用户非正常退出,动态刷新(不用meta),表情,密语……
    用数据库的话也许可以简单了很多
    但是不用数据库的话,非得累死你
    另外关于javascript的还有很多东西需要写呢
    反正这个是我以前写聊天室的体会,不知道大家写聊天室又怎么样?
      

  7.   

    用c呀,不是指那种不支持单线程的cgi哦
      

  8.   

    用SOCKET是最好的,PHP +JS也可以写出来,不过效果和速度比SOCKET的
    差很多啊,其实还可以用SERVER-PUSH的技术,有几个网站的聊天室就是
    模拟这种技术的,可以看看PHP的关于控制BUFFER的几个函数
      

  9.   

    聊天室对语言的要求很高,不要用PHP写……
    如果你对TCP/IP不是很了解,也不要用C/C++写……
    虽然我不会JAVA,但写chat,它是一个性价比最高的语言:性能/时间
      

  10.   

    163.com好像有一部分是用php写的 啊