文章來源:PHP 世紀(jì)網(wǎng) 根據(jù)許多網(wǎng)友需求,特地把我站的這個(gè)模擬 OICQ 的在線聊天的東西獻(xiàn)給大家!
1 用戶必須注冊(cè)登陸,在數(shù)據(jù)庫 userinfo 里面保存如下幾個(gè)字段 Name 不用問了,這是登陸用的用戶名,必須唯一 Password 登陸密碼 NickName 用戶昵稱,也就是顯示的名字 Face 存放著用戶頭像的編號(hào),比如 01,代表 /images/face/01.gif 頭像文件 OnlineStatus 用戶是否在線的標(biāo)志,在用戶登陸的時(shí)候設(shè)置為 1 CurrentDate 用戶最后訪問/更新的時(shí)間,用于判斷用戶是否在線
聊天紀(jì)錄 forumtalk 的結(jié)構(gòu)為 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 是發(fā)送人的 Name receiver 是接受人的 Name date 是發(fā)言的時(shí)間 readsign 發(fā)言是否已經(jīng)閱讀過 body 發(fā)言內(nèi)容
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."位朋友在線,按頭像發(fā)短信息:"; 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='代號(hào):".$onlineuser['Name']."\n昵稱:".$onlineuser['NickName']."\n來訪:".$onlineuser['EnterTimes']."'></a>"; } ?>
其中的 onClick 用于彈出發(fā)送消息的對(duì)話窗口,大家可以在網(wǎng)頁的源代碼里面看到
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!