用PHP+MySql编写聊天室
大家好!好久没有看到大家了,上次写了用PHP的通过文件操作的聊天室,当然是漏洞百出的,而且每一次刷新屏幕都很糟糕的!我想了好久,是不是能有一种方法不要刷新,就能取得发言的信息了?多用一个框架就能实现这个效果了,即多用一个框架我们称为getmsg,我们让getmeg去取得信息而且保证每一次取得的信息是最新的,就是上次取得的发言就不要了,上次我编的就是每一次取得信息都是重复的,这样效果不好。
我的设计思想是:每一次发言,都把它提交到服务器上,然后保存到一个数据库里,每格几秒钟getmsg就去服务器上取得 最新发言数据,并保证上次取得的发言就不要取下来了,然后把取下来的发言叠加到一个专门显示发言的窗口(listmsg)去。这样我们就感觉listmsg窗口不会有重刷新的感觉而且,只是看到发言信息不断加进去,这样就有很好的效果,
怎样在一个框架把信息加到另个框架去了?用JavaScript就可以实现这个想法的:
当然你得在mysql里建两个表,一个表用于保存发言信息,一个表用于保存几个在线的,在列在线人数时,我们让它每个60秒刷新一次,并把一分钟以前的发言删掉,并看某个发言人是不是很长时间没发言了,是的话,就删掉他,
由于表的子段很简单,在这里就不要写出来了,看程序就会知道了。这个程序在网上网下测试的效果都很好!
表的名字是:chat和chat_getmsg
if(!isset($username))
$username="guest";
$conid=mysql_connect("localhost","yourcounter","password");
mysql_select_db("yourdadabase",$conid);
$dstr=date("YmdHis");
$sql="insert chat_getmsg (username,shijian) values ('$username','$dstr')";
mysql_query($sql,$conid);
$sql="update chat_getmsg set shijian='$dstr' where username='$username'";
mysql_query($sql,$conid);
mysql_close($conid);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
