Home >Backend Development >PHP Tutorial >显示当前在线人数_PHP

显示当前在线人数_PHP

WBOY
WBOYOriginal
2016-06-01 12:31:341710browse
  

  介绍:

  我们可以通过程序来显示当前的数据。

  注意的两点: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

  注意:把$应为半角
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn