这篇文章主要介绍了简单的php+mysql聊天室实现方法,详细介绍了数据库,框架页面,登录及信息的发布、展示功能实现技巧,并附带了完整源码供读者下载参考,需要的朋友可以参考下
本文实例讲述了简单的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; -- ---------------------------- -- Rec<span style="color:transparent">来源gaodai#ma#com搞*代#码网</span>ords 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');
二、框架页面如下:
<title>简单的php+mysql聊天室--框架页</title>
三、用户登陆页面login.php如下:
<title>简单的php+mysql聊天室--登陆页</title> <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"> </td></tr><tr> <td bgcolor="#F5E6C1"> </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>
四、用户发言页面speak.php如下:
<title>简单的php+mysql聊天室--发言页</title> <table width="80%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="2"></td></tr></table> 发言表情:
五、显示聊天室内容页show.php如下:
<title>简单的php+mysql聊天室--显示留言页</title> <?php //最新发言显示在最下面 $sql="select * from chat order by chtime asc"; $result=mysql_query($sql); $total=mysql_num_rows($result); $info=($total/15-1)*15; if($total <table width="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"></td><td width="42" align="center" bgcolor="#F5E6C1" class="font"></td><td width="56" align="left" bgcolor="#F5E6C1" class="font">发言内容:</td><td width="160" align="left" bgcolor="#F5E6C1" class="font"></td><td width="56" align="left" bgcolor="#F5E6C1" class="font">发言时间:</td><td width="244" align="left" bgcolor="#F5E6C1" class="font"></td></tr></table><table width="100" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="5"></td></tr></table>
完整实例代码点击此处本站下载。
希望本文所述对大家PHP程序设计有所帮助。
以上就是简单的php+mysql聊天室实现方法(附源码)的详细内容,更多请关注gaodaima搞代码网其它相关文章!