本文实例讲述了简单的php+mysql聊天室实现方法。分享给大家供大家参考,具体如下:
这里介绍的程序分为 8 个文件:
frameset框架页面:index.php
显示聊天室内容页:show.php
用户登陆页面:login.php
用户发言页面:speak.php
数据库配置文件:config.php
页面美化样式:style.css
数据库文件:chat.sql
发言表情包:face/
分别介绍如下:
一、数据库文件chat.sql如下:
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `chat` -- ---------------------------- DROP TABLE IF EXISTS `chat`; CREATE TABLE `chat` ( `chtime` datetime default NULL, `nick` char(10) NOT NULL, `words` char(150) default NULL, `face` int(11) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=gb2312; -- ---------------------------- -- Records of chat -- ---------------------------- INSERT INTO chat VALUES ('2013-03-21 04:15:14', 'smiling', '测试显示发言', '3'); INSERT INTO chat VALUES ('2013-03-21 04:46:26', 'smiling', '时间有问题,', '5'); INSERT INTO chat VALUES ('2013-03-21 04:47:28', 'php新手', '新手来了。', '1'); INSERT INTO chat VALUES ('2013-03-21 04:55:19', 'php新手', '显示正确啦', '6'); INSERT INTO chat VALUES ('2013-03-21 17:12:47', 'php新手', '正确显示时间', '5'); INSERT INTO chat VALUES ('2013-03-21 17:23:19', 'php新手', '时间显示正确。', '7'); INSERT INTO chat VALUES ('2013-03-21 17:23:29', 'php新手', '哈哈', '1'); INSERT INTO chat VALUES ('2013-03-22 08:28:00', '', '今天再来看看。', '3');
二、框架页面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>简单的php+mysql聊天室--框架页</title> </head> <frameset rows="*,80" cols="*" framespacing="0" bordercolor="#E1D1AE"> <frameset rows="*" cols="*,284"> <frame src="/UploadFiles/2021-04-02/show.php">三、用户登陆页面login.php如下:
<html> <head> <title>简单的php+mysql聊天室--登陆页</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="80%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table> <table width="250" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CBB486"> <tr> <td height="30" align="center" bgcolor="#F5E6C1"> <"tj"] == "out"){ setcookie ("nick", "", time() - 3600); header("refresh:0; URL='login.php'"); } if($_POST["submit"]){ setcookie("nick",$nick); //用cookie记录用户昵称,也可以用SESSION header("refresh:0; URL='login.php'"); } "nick"]){echo "欢迎您 ".$_COOKIE["nick"]." <a href=";}else{echo "请输入您的昵称";}"#F5E6C1"> <form action="" method="post"> <input type="text" name="nick" cols="20"> <input type="submit" name="submit" value="登录"> </form></td> </tr> </table> <table width="80%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table> <table width="250" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CBB486"> <tr> <td height="70" bgcolor="#F5E6C1" class="login">程序说明:因本聊天室是作者仅花了一天时间而写的程序,所以仅适合新手练习研究,高手可以进行绕行,新手可以在本基础上进行增加发言IP和其它字段功能,最主要的是理解本程序的制作原理。欢迎新手朋友加入夏日源码交流群:<SPAN id="qid">101140934</SPAN></td> </tr> </table> </body> </html>四、用户发言页面speak.php如下:
<html> <head> <title>简单的php+mysql聊天室--发言页</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="80%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="2"></td> </tr> </table> <form action="show.php" target="mainFrame" method="post"> 发言表情: <input type="radio" value="1" name="face" checked="checked" /> <img src="/UploadFiles/2021-04-02/PIC1.GIF">五、显示聊天室内容页show.php如下:
<"insert into chat(chtime,nick,words,face)values(now(),'$nick','$words','$face')";//插入SQL语句 mysql_query($query,$link_ID); //发送留言到数据库 header("refresh:0; URL='show.php'"); } "style.css" rel="stylesheet" type="text/css" /> <meta http-equiv="refresh" content="5;url=show.php"> </head> <body> <"select * from chat order by chtime asc"; $result=mysql_query($sql); $total=mysql_num_rows($result); $info=($total/15-1)*15; if($total<15){ $str="select * from chat order by chtime asc;" ; //查询字符串 }else{ $str="select * from chat order by chtime asc limit $info,15;" ; //查询字符串 } $result=mysql_query($str,$link_ID); //送出查询 while($row=mysql_fetch_array($result)){ "700" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#CBB486"> <tr> <td width="33" align="left" bgcolor="#F5E6C1" class="font">昵称:</td> <td width="41" align="center" bgcolor="#F5E6C1" class="font"><""){echo "游客";}else{echo $row[nick];}"42" align="center" bgcolor="#F5E6C1" class="font"><img src="/UploadFiles/2021-04-02/PIC<">本站下载。希望本文所述对大家PHP程序设计有所帮助。
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]