日期:2012-07-18  浏览次数:20660 次

  本教程属于原载,转载请注明出自网页教学网

  介绍:

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

  注意的两点:1.必须把下列代码放到扩展名为.PHP的文件中;2.在你的服务器上运行代码时,你的服务器必须支持MYSQL数据库。

  代码如下:

  下列代码放到你想显示信息的地方。

<?php

//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<$timeout");

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

  注意:把$应为半角