• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 模擬OICQ的實現思路和核心程序

    發表于:2007-07-14來源:作者:點擊數: 標簽:
    根據許多網友 需求 ,特地把我站的這個模擬 OICQ 的在線聊天的東西獻給大家! 1 用戶必須注冊登陸,在 數據庫 userinfo 里面保存如下幾個字段 Name 不用問了,這是登陸用的用戶名,必須唯一 Password 登陸密碼 NickName 用戶昵稱,也就是顯示的名字 Face 存
    根據許多網友需求,特地把我站的這個模擬 OICQ 的在線聊天的東西獻給大家!

    1 用戶必須注冊登陸,在數據庫 userinfo 里面保存如下幾個字段
    Name 不用問了,這是登陸用的用戶名,必須唯一
    Password 登陸密碼
    NickName 用戶昵稱,也就是顯示的名字
    Face 存放著用戶頭像的編號,比如 01,代表 /images/face/01.gif 頭像文件
    OnlineStatus 用戶是否在線的標志,在用戶登陸的時候設置為 1
    CurrentDate 用戶最后訪問/更新的時間,用于判斷用戶是否在線

    聊天紀錄 forumtalk 的結構為
    CREATE TABLE forumtalk (
    id int(11) NOT NULL auto_increment,
    sender varchar(20) NOT NULL,
    receiver varchar(20) NOT NULL,
    date int(11) DEFAULT '0' NOT NULL,
    readsign tinyint(4) DEFAULT '0' NOT NULL,
    body varchar(200) NOT NULL,
    PRIMARY KEY (id),
    UNIQUE id_2 (id),
    KEY id (id)
    );
    其中 sender 是發送人的 Name
    receiver 是接受人的 Name
    date 是發言的時間
    readsign 發言是否已經閱讀過
    body 發言內容

    2 顯示在線用戶的頭像
    <?
    $onlineresult = mysql_query("select Name,NickName,Face,EnterTimes from userinfo where OnlineStatus=1 and CurrentDate >".(date("U")-120));
    $onlinenumber = mysql_num_rows($onlineresult);
    echo "歡迎光臨,共有:".$onlinenumber."位朋友在線,按頭像發短信息:";
    for($i=0;$i<$onlinenumber;$i++)
    {
    if(!$onlineuser = mysql_fetch_array($onlineresult))break;
    echo "<a onClick=MM_openBrWindow('shortalk.php?talkto=".$onlineuser['Name']."','".$onlineuser['Name']."','width=300,height=250')><img src="/Files/BeyondPic/2005-12/19/05121906592254661.gif" width=20 height=20 ";
    if($name == $onlineuser['Name'])echo "border=1 ";
    echo " title='代號:".$onlineuser['Name']."\n昵稱:".$onlineuser['NickName']."\n來訪:".$onlineuser['EnterTimes']."'></a>";
    }
    ?>

    其中的 onClick 用于彈出發送消息的對話窗口,大家可以在網頁的源代碼里面看到
    3 在線用戶的信息掃描和更新
    在網頁中使用內置框架來調用掃描和更新程序,這行也能在網頁源代碼里面看到!
    <iframe name=flush src="userflush.php" width="0" height="0" frameborder="0" scrolling="NO" marginwidth="0" marginheight="0" hspace="0" vspace="0"></iframe>

    4 信息掃描和更新程序 userflush.php

    <?
    session_start();
    mysql_connect("localhost","","");
    mysql_select_db("php2000");
    $delaytime=0;

    // 查找新的發言
    $query = "select * from forumtalk where readsign=0 and receiver='$name'";
    $result = mysql_query($query);
    if( mysql_num_rows($result) > 0)
    {
    // 讀取和顯示彈出窗口
    $msg = mysql_fetch_array($result);
    $numberfriend = $msg['id'];
    echo "<script language=javascript>window.open('shortalk.php?action=view&talknumber=$numberfriend','_blank','width=300,height=250')</script>";
    }

    // 設置當前用戶的最新時間標志,表示它在線
    mysql_query("update userinfo set currentdate=".date("U")." where name='$name'");

    // 設置刷新時間間隔為15秒
    echo "<meta http-equiv='refresh' content='15;url=userflush.php'>";
    ?>  
    5 聊天信息的發送、閱讀和回復程序 - shortalk.php

    <?
    require("require.php"); // 判斷用戶是否合法在線的公用程序
    ?>
    <html>
    <head>
    <title>短信息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    td {font-size:9pt}
    </style>
    <script language="Javascript">
    <!--
    function docheck() {
    if (document.sendmsg.replymessage.value=="") {
    alert("缺少內容:需要輸入您的留言內容");
    document.sendmsg.replymessage.focus();
    return(false);
    }
    return (true);
    }

    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    //-->
    </script>
    </head>

    <body bgcolor="#DDDDFF"leftmargin="0" topmargin="0" background="phpchat_images/cloudtile.jpg">
    <?
    if($action == "view")
    {
    $tmp = mysql_fetch_array(mysql_query("select sender,body,date from forumtalk where id=$talknumber and receiver='$name'"));
    $msg = $tmp['body'];
    $message = ereg_replace("
    ","\r\n",$msg);
    mysql_query("update forumtalk set readsign=1 where id=$talknumber");
    $sendernickname = mysql_fetch_row(mysql_query("select nickname from userinfo where name='".$tmp['sender']."'"));
    ?>
    <table width="300" border="0" cellspacing="0" cellpadding="0" height="200" bgcolor="f0f0f0">
    <tr>
    <td colspan="2" height="20" bgcolor="99clearcase/" target="_blank" >cc99" align="center">查看短信息</td>
    </tr>
    <tr>
    <td colspan="2" height="20"><?echo date("m月d日 h:i",$tmp['date'])." ".$sendernickname[0]?> 給你[<?echo $name?>]留言:</td>
    </tr>
    <form name=viewtalk action=shortalk.php method=post>
    <input type=hidden name=talkto value=<?echo $tmp['sender']?>>
    <input type=hidden name=action value=send>
    <input type=hidden name=talknumber value=<?print($talknumber)?>>
    <tr align="center">
    <td colspan="2" height="146" valign="top">
    <textarea name="textfield" cols="40" rows="11" readonly><?print($message)?></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" name="toreply" value="回復留言 Enter">
    <a href="#" onClick="MM_openBrWindow('memberviewtalk.php?talkto=<?echo $tmp['sender']?>','viewtalk','scrollbars=yes')">聊天紀錄</a> </td>
    </tr>
    </form>
    </table>
    <script language="Javascript">
    document.viewtalk.toreply.focus();
    </script>
    <?
    }
    else if ($action == "sendbegin")
    {
    $replymessage = ereg_replace("\r\n","
    ",$replymessage);
    $replymessage = ereg_replace(">",">",$replymessage);
    $replymessage = ereg_replace("<","<",$replymessage);
    $replymessage = substr($replymessage,0,2000);
    mysql_query("insert into forumtalk (sender,receiver,body,date) values ('$name','$talkto','$replymessage',".date("U").")");
    print("<script language='javascript'>window.close()</script>");
    }
    else
    {
    ?>
    <table width="300" border="0" cellspacing="0" cellpadding="0" height="200" bgcolor="f0f0f0">
    <form name=sendmsg action=shortalk.php method=post OnSubmit=return(docheck());>
    <input type=hidden name=action value=sendbegin>
    <tr align="center">
    <td colspan="2" height="20" bgcolor="99cc99">發送短信息</td>
    </tr>
    <tr align="center">
    <td colspan="2" height="20">發言對象:
    <select name="talkto">
    <?
    $result = mysql_query("select name,nickname from userinfo where onlinestatus=1");
    while($msg=mysql_fetch_array($result))
    {
    if($msg['name']==$talkto)
    echo "<option value='".$msg['name']."' selected>".$msg['nickname']."</option>\n";
    else
    echo "<option value='".$msg['name']."'>".$msg['nickname']."</option>\n";
    }
    ?>
    </select>
    請短于500字符 </td>
    </tr>
    <tr align="center">
    <td colspan="2" height="146" valign="top">
    <textarea name="replymessage" cols="40" rows="9"></textarea>
    </td>
    </tr>
    <tr align="center">
    <td colspan="4">
    <?
    if($talknumber != "")
    {
    print("<input type=button name=review value='查看前一留言 Alt+P' accesskey='p' onClick='javascript:history.go(-1)'>");
    }
    ?>
    <input type="submit" name="reply" value="開始新的發送留言 Alt+S" accesskey='s'>
    <a href="#" onClick="MM_openBrWindow('memberviewtalk.php?talkto=<?echo $talkto?>','viewtalk','scrollbars=yes')">聊天紀錄</a></td>
    </tr>
    </form>
    </table>
    <script language="Javascript">
    document.sendmsg.replymessage.focus();
    </script>
    <?
    }
    ?>
    </body>
    </html>  

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>