文章來源:PHP 世紀網 根據許多網友需求,特地把我站的這個模擬 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='images/face/".$onlineuser['Face'].".gif' width=20 height=20 "; if($name == $onlineuser['Name'])echo "border=1 "; echo " title='代號:".$onlineuser['Name']."\n昵稱:".$onlineuser['NickName']."\n來訪:".$onlineuser['EnterTimes']."'></a>"; } ?>
其中的 onClick 用于彈出發送消息的對話窗口,大家可以在網頁的源代碼里面看到
|