...
<?
$user = "root";
$pass = "";
$host = "localhost";
$base = "chat";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($base) or die(mysql_error());
switch ($_GET['act']) {
default:
function onLine() {
$distance = 300;
$ip = $_SERVER['REMOTE_ADDR'];
$ua = $_SERVER['HTTP_USER_AGENT'];
$query = "DELETE FROM `online` WHERE 'stamp'+$distance < ".time()." OR (`ip` = '$ip' OR `ua` = '$ua')";
mysql_query($query) or die(mysql_error());
$query = "INSERT INTO `online`(`stamp`,`ip`,`ua`) VALUES('".time()."','".$ip."','".$ua."')";
mysql_query($query) or die(mysql_error());
$result = mysql_query("SELECT COUNT(*) FROM `online`");
$row = mysql_fetch_array($result,MYSQL_BOTH);
return ($row[0]);
}
echo '<a href="online.php?act=online">На сайте: ' . onLine() . ' чел</a>';
break;
case 'online':
$i = 0;
$sql = mysql_query("SELECT * FROM `online` ORDER BY `id` DESC ");
while($guest = mysql_fetch_assoc($sql)){
++$i;
echo '<b>' . $i . '</b> IP: ' . $guest['ip'] . ' / User-Agent: ' . $guest['ua'] . '<hr />';
}
break;
}
?>