A simple php+mysql chat room implementation method is described in this paper. Share to everyone for your reference, specific as follows:
The procedures described here are divided into 8 files:
Frameset frames page: index.php
Show Chat Room content page: show.php
User Login page: login.php
User Speaking page: speak.php
Database configuration file: config.php
Page beautification style: Style.css
Database files: Chat.sql
Speech Expression Package: face/
The following are described separately:
First, the database documents Chat.sql as follows:
SET foreign_key_checks=0;
--------------------------------Table structure for ' chat '------------------------------DROP Table IF EXISTS ' chat '; CREATE TABLE ' chat ' (' chtime ' datetime default NULL, ' Nick ' char () not NULL, ' words ' char ($) default NULL, ' Face
' Int (one) default NULL engine=innodb default charset=gb2312; --------------------------------Records of chat------------------------------INSERT into chat VALUES (' 2013-03-21 04
: 15:14 ', ' smiling ', ' Test show speak ', ' 3 ');
INSERT into chat VALUES (' 2013-03-21 04:46:26 ', ' smiling ', ' time has a problem, ', ' 5 '); INSERT into chat VALUES (' 2013-03-21 04:47:28 ', ' php novice ', ' novice coming up.
', ' 1 ');
INSERT into chat VALUES (' 2013-03-21 04:55:19 ', ' php novice ', ' show Right ', ' 6 ');
INSERT into chat VALUES (' 2013-03-21 17:12:47 ', ' php novice ', ' Show time correctly ', ' 5 '); INSERT into chat VALUES (' 2013-03-21 17:23:19 ', ' php novice ', ' time is displayed correctly.
', ' 7 ');
INSERT into chat VALUES (' 2013-03-21 17:23:29 ', ' php novice ', ' haha ', ' 1 '); INSERT into chat VALUES (' 2013-03-22 08:28:00 ', ', ' and see again today.)
', ' 3 ');
Second, the frame page is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 frameset//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" >
Third, the user landing page login.php as follows:
Four, the user statements page speak.php as follows:
Five, show chat room content page show.php as follows:
<?php require_once (' config.php ');?> <?php if ($words) {$query = INSERT into chat (chtime,nick,words,face) Values (now (), ' $nick ', ' $words ', ' $face ');/INSERT SQL statement mysql_query ($query, $link _id); Send a message to the database header ("refresh:0; Url= ' show.php '); ?>
Full instance code click here to download the site.
I hope this article will help you with the PHP program design.