显示当前在线人数_PHP
- WBOY原创
- 2016-06-01 12:31:341709浏览
介绍:
我们可以通过程序来显示当前的数据。
注意的两点:1.必须把下列代码放到扩展名为.PHP的文件中;2.在你的服务器上运行代码时,你的服务器必须支持MYSQL数据库。
代码如下:
下列代码放到你想显示信息的地方。
//EDIT THIS
$server = "localhost";
$db_user = "database username";
$db_pass = "database password";
$database = "database";
$timeoutseconds = 300;
//STOP EDITING
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
mysql_connect($server, $db_user, $db_pass);
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);
mysql_close();
if($user == 1) {
print("$user\n");
} else {
print("$user\n");
}
?>
最后在MYSQL中修改你的 username 和 passwords
注意:把$应为半角
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn