How to implement PHP Web chat software

Source: Internet
Author: User
Tags button type
This article mainly introduces the PHP Web version of the chat software implementation code, can achieve anonymous chat, interested in small partners can refer to

Specific content is as follows

1. index.html

2. action.php

<?php $link = mysqli_connect (' localhost ', ' root ', ' 123 ', ' Test '), Mysqli_query ($link, ' Set names UTF8 '); $info = Array () ; Header ("content-type:text/html; Charset=utf-8 "); $id =$_get[' Maxid '); $data = Mysqli_query ($link," select * from Talk where id> $id "); while ($array = mysq LI_FETCH_ASSOC ($data)) {$info [] = $array;};  echo Json_encode ($info);

3. Chat.sql

DROP TABLE IF EXISTS ' talk '; CREATE TABLE ' Talk ' (' id ' int (ten) unsigned not NULL auto_increment COMMENT ' id ', ' send ' varchar (ten) CHARACTER SET UTF8 DE FAULT null COMMENT ' sender nickname ', ' IP ' varchar (CHARACTER) Set UTF8 DEFAULT NULL, ' content ' varchar ($) CHARACTER set UTF8 DE FAULT null, ' time ' varchar (default NULL, PRIMARY KEY (' id ')) engine=innodb auto_increment=52 default Charset=utf8;

4. add.php

<?php/** * @ function inserts the form into the database */$content =$_post[' content '];p rint_r ($_post); $time = Date ("Y-m-d h:i:s", Time (0)); $link = Mysqli_connect (' localhost ', ' root ', ' 123 ', ' Test '), Mysqli_query ($link, ' Set names UTF8 '); $ip = $_server["REMOTE_ADDR"] ; $sql = "INSERT into Talk VALUES (NULL, ' Anonymous ', ' $ip ', ' $content ', ' $time ') '; $data = Mysqli_query ($link, $sql); echo" $content "If ($data) echo" 1 "; else  echo "0";

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.