首先是创建MYSQL数据库表。
CREATE TABLE tablename (
field type(max_length) DEFAULT 'default_value' (NOT) NULL
}
可以使用的SQL语句。
CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);
下面我们开始使用PHP脚本,首先定义MYSQL的信息。
server = "localhost"; //你的服务器
db_user = "root"; //你的mysql的用户名
db_pass = "password"; //你的mysql的密码
database = "users"; //表的名字
设置统计的时间(多少秒内在线人数)
timeoutseconds = 300;
取当前时间。
timestamp = time();