<?PHP
/*
CREATE TABLE `db_online` (
`ip` char(20) default NULL,
`time` char(20) NOT NULL default '',
`name` char(200) NOT NULL default '游客'
) TYPE=MyISAM
*/
//粗略計算在線時間,bug:ip相同(局域網->外部網)者,只記錄一人。不過幾率很少
session_start();
//超時時間
$out_time=300;//60*5
$uesr_name=$_SESSION['uesr_name'];
$now=time();
$online="db_online";
$ip=$_SERVER["REMOTE_ADDR"];
mysql_connect("localhost","root","");
mysql_select_db("數據庫");
//刪除過時用戶.
mysql_query("delete from `$online` where ($now-`time`)>$out_time or `name`='$uesr_name' or `ip`='$ip' ");
if($uesr_name){
mysql_query(" INSERT INTO `$online` (`ip`, `time`, `name`) VALUES ('$ip','$now','$uesr_name') ");
}else{
mysql_query(" INSERT INTO `$online` (`ip`, `time`, `name`) VALUES ('$ip','$now','游客') ");
}
?>