刚用PHP写了一个网站在线人数的程序,请大家进来指点下!
刚用PHP写了一个网站在线人数的程序,请大家进来指点下!kT0zo Y Z*[z我是用PHP+MYSQL来写的,原理:网站在线人数的程序代码+后台有MYSQL数据库支持,可以直接统计出网站当前的在线人数。8{}j lA,G/C
首先我创建MYSQL数据库表。1D*iu(MM8G
CREATE TABLE tablename ( Lz.S#c[d
field type(max_length) DEFAULT 'default_value' (NOT) NULL
}可以使用的SQL语句。+khUA&iR+HHg
CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,bq(inv[lJQ*_
ip varchar(40) NOT NULL,8Dq7^!c D
file varchar(100) NOT NULL,(BA7jW+U G[;{
PRIMARY KEY (timestamp),-Cly)r]t
KEY ip (ip),
KEY file (file)
);下面我们是PHP脚本,首先我定义MYSQL的信息。
$server = "localhost"; //你的服务器 A#YM-|ygjq,n
$db_user = "root"; //你的mysql的用户名
$db_pass = "password"; //你的mysql的密码
$database = "users"; //表的名字设置统计的时间(多少秒内在线人数)
$timeoutseconds = 300;取当前时间。
$timestamp = time();上面的完整代码:g3dyknfB;B)\
<?php
$server = "localhost"; //your server {&i"Vt2Z.s qp0J
$db_user = "root"; //your mysql database username
$db_pass = "password"; //your mysql database password if anyl,o_$v6U j
$database = "users"; //the db name
$timeoutseconds = 300;//timeoutseconds limit"u3r!p1znXI
//get the current time