Simple Php+mysql Chat Room implementation method (attached source), MySQL chat room _php Tutorial

Source: Internet
Author: User
Tags setcookie

Simple Php+mysql Chat Room implementation method (attached source), MySQL chat room


In this paper, a simple php+mysql chat room implementation method is described. Share to everyone for your reference, as follows:

The program described here is divided into 8 files:

Frameset Frame page: index.php

Show Chat Room content page: show.php

User Login page: login.php

User Statements page: speak.php

Database configuration file: config.php

Page beautification style: Style.css

Database file: Chat.sql

Speech Expression Pack: face/

The following are presented separately:

One, the database file 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 (TEN) 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-0 3-21 04:46:26 ', ' smiling ', ' time has a problem, ', ' 5 '); INSERT into chat VALUES (' 2013-03-21 04:47:28 ', ' php novice ', ' novice '). ', ' 1 '); INSERT into chat values (' 2013-03-21 04:55:19 ', ' php novice ', ' show correct ', ' 6 '); INSERT into chat values (' 2013-03-21 17:12: ' PHP novice ', ' correct display time ', ' 5 '); INSERT into chat VALUES (' 2013-03-21 17:23:19 ', ' php novice ', ' time display correct. ', ' 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 ') , ', ' Look again today. ', ' 3 '); 

Second, the framework page is as follows:

 
  Simple Php+mysql Chat Room--frames page       
 
  
   
  <body></body>
 
  

Third, the user landing page login.php as follows:

<title>Simple Php+mysql Chat Room--landing page</title>
 
  
 
 
 
<?php if ($_get["TJ"] = = "Out") {Setcookie ("Nick", "", Time ()-3600); Header ("refresh:0; Url= ' login.php '); } if ($_post["submit"]) {Setcookie ("Nick", $nick);//Use a cookie to record a user's nickname, or use the session header ("REFRESH:0; Url= ' login.php '); }?> <?php if ($_cookie["Nick"]) {echo "Welcome". $_cookie["Nick"]. "Exit the room"; Else{echo "Please enter your nickname";}? >
Program Description: Because this chat room is the author only spent a day and write the program, so only suitable for beginners to practice research, Master can bypass, novice can be on this basis to increase the speech IP and other fields function, the most important is to understand the production principle of the program. Welcome novice friends to join the summer source Exchange Group:101140934

Iv. User Statement page speak.php as follows:

Simple Php+mysql Chat Room--speak page
 
  
 
  
  

Five, display the chat room content page show.php as follows:

<?php require_once (' config.php ');? ><?phpif ($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 '); }?><title>Simple Php+mysql Chat room--Show Message page</title>
 
  
 
 
  
 <?php//The latest statement is shown at the bottom $sql = "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;";//query string}else{$str = "SELECT * FROM Chat order by chtime ASC limit $info, 15; "; Query string} $result =mysql_query ($str, $link _id); Send query while ($row =mysql_fetch_array ($result)) {?>
 
 
Nickname: <?php if ($row [Nick] = = "") {echo "visitor";} Else{echo $row [Nick];}? > . GIF "width=" "height=" > Content of the statement: <?php echo $row [words];? > Speaking time: <?php echo $row [Chtime];? >
<?php}?>

Full instance code click here to download this site.

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Use Php+mysql to build chat room function Instance code
    • Write a chat room with Php+mysql
    • Chat room Php&mysql (Fri)
    • Chat room Php&mysql (Thu)
    • Chat room Php&mysql (iii)
    • Chat room Php&mysql (b)
    • Chat room Php&mysql (i)
    • Chat room Php&mysql (vi)
    • Chat room design based on Php+mysql

http://www.bkjia.com/PHPjc/1088780.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088780.html techarticle Simple Php+mysql Chat Room implementation method (with source code), MySQL chat room This article describes a simple php+mysql chat room implementation method. Share to everyone for your reference, as follows: this ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.