<?PHP
session_start();
header( 'Content-type: text/html; charset=windows-1251' );

if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');

$id_user = (isset($_SESSION["iduser"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["iduser"]))) ? intval(trim($_SESSION["iduser"])) : false;

#Функции
function online_us($ip, $id)  {
mysql_query("INSERT IGNORE INTO `b_online` (`user`, `idus`, `time`) VALUES ('$ip', '$id', '".(time()+300)."') ON DUPLICATE KEY UPDATE `time` = VALUES(`time`), `idus` = VALUES(`idus`)") or die(mysql_error());
mysql_query("DELETE FROM `b_online` WHERE `time` < '".time()."' ") or die(mysql_error());
}
function ip_us(){ return preg_replace('/[^0-9.]/', '', trim($_SERVER['REMOTE_ADDR'])); }

if(date("H") >= "00" && date("H") < "08"){$x = "300";
}elseif(date("H") >= "08" && date("H") < "12"){$x = "700";
}elseif(date("H") >= "12" && date("H") < "15"){$x = "500";
}elseif(date("H") >= "15" && date("H") < "18"){$x = "600";
}else{$x = "700";}
#Онлайн вывод
if($_POST['func'] == 'online_us'){
online_us(ip_us(), $id_user);
}
if($_POST['func'] == 'online_views'){
echo (int)@mysql_num_rows(mysql_query("SELECT `user` FROM `b_online`")); //*3+$x
}
}
?>   