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.