<?php
/*list($msec,$sec)=explode(chr(32),microtime());
$HeadTime=$sec+$msec; */
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include "config.php";
include './inc/config.inc.php';
include './inc/functions.inc.php';
connect_to_db();
// ----------------------------- проверка ввода id -------------------------- //
if (empty($_GET['uid'])) {
$img = @imageCreateFromGIF("./img/errors.gif");
Header("Content-type: image/gif");
ImageGIF($img);
ImageDestroy($img);
exit;
}
// --------------------------------------------------------------------------- //
$uid = dig($_GET['uid']);
$uid = (int)$uid;
// ------------------------- проверка существования учетной записи ----------- //
$result = mysql_query("SELECT `link`,`cat_id` FROM `users` WHERE `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
if (empty($row)) {
$img = @imageCreateFromGIF("./img/errors.gif");
Header("Content-type: image/gif");
ImageGIF($img);
ImageDestroy($img);
exit;}
$cat_id = $row["cat_id"];
// --------------------------------------------------------------------------- //
// --------------------- Обновление даты пользование топом ------------------- //
mysql_query("UPDATE `users` SET `date` = '" . time () . "' WHERE `uid` = " . $uid . " LIMIT 1;");
// --------------------------------------------------------------------------- //
// --------------------- получаем ip посетителя ------------------------------ //
$ip = $_SERVER['REMOTE_ADDR'];
$ua = $_SERVER['HTTP_USER_AGENT'];
$ip = northwest($ip);
$ua = formes($ua);
$browser = explode("/", $ua);
$user_browser = (string)$browser[0];
// --------------------------------------------------------------------------- //
// =================== Определение тела и учет в статистике
include "mod_telinfo.php";
// =================== Определение оператора и учет в статистике
include "mod_operators.php";
// ------------------ текущий час, день недели и дата ------------------------ //
$hour = date("H");
$day = date("d");
$today = date("Ymd");
// --------------------------------------------------------------------------- //
// ------------------------- обнулялка хостов ----------------------------
// извлекаем время последней записи в счетчик хостов
$result = mysql_query("SELECT `time` FROM `hits_time` WHERE `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
// если время отсутствует, запоминаем
if (empty($row)) {
@mysql_query("INSERT INTO `hits_time` VALUES ('" . $uid . "','" . $today . "');");
$reset_time = $today;
} else $reset_time = $row[0];
// удаляем записи ip старее суток
if ($today != $reset_time) {
@mysql_query("DELETE FROM `hits_ip` WHERE `uid`='" . $uid . "';");
@mysql_query("UPDATE `hits_time` SET `time` = '" . $today . "' WHERE `uid`='" . $uid . "';");
}
// --------------------------------------------------------------------------- //
// ------------------------------ часовая статистика -------------------------
// данные за текущий час
$result = mysql_query("SELECT `count`,`host` FROM `count_24` WHERE `hour`='" . $hour . "' AND `date`='" . $today . "' AND `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row)) {
$res = mysql_query("SELECT count(*) FROM `count_24` WHERE `uid`='" . $uid . "';");
$data = mysql_fetch_row($res);
$count_rows = $data[0];
if ($count_rows >= 24) @mysql_query("DELETE FROM `count_24` WHERE `uid`='" . $uid . "' ORDER BY `id` ASC LIMIT 1;");
mysql_query("INSERT INTO `count_24` (`id`, `uid`, `date`, `hour`, `count`, `host`) VALUES ('', '" . $uid . "', '" . $today . "', '" . $hour . "', '0', '0');");
$hour_count = 0;
$hour_host = 0;
} else {
$hour_count = $row[0];
$hour_host = $row[1];
}
$hour_count++;
// --------------------------------------------------------------------------- //
// ---------------------------- посещения за месяц --------------------
$today = date("Ym");
// данные за текущий месяц
$result = mysql_query("SELECT `count`,`host` FROM `months` WHERE `date`='" . $today . "' AND `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
// поверка наличия записи в базе
if (empty($row)) {
mysql_query("INSERT INTO `months` (`id`, `uid`, `date`, `count`, `host`) VALUES ('','" . $uid . "','" . $today . "',0,0);");
$this_month_count = 0;
$this_month_host = 0;
} else {
$this_month_count = $row[0];
$this_month_host = $row[1];
}
$this_month_count++;
// -------------------------- недельная статистика----------------
// $week_day = date("w");
$today = date("Ymd");
// получаем дату обнуления недельной статистики
$result = mysql_query("SELECT `next_mon` FROM `weeks` WHERE `uid`='" . $uid . "' ORDER BY `id` ASC LIMIT 1;");
$row = mysql_fetch_row($result);
if (empty($row)) {
$nextMonday = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + 32));
} else $nextMonday = $row[0];
// если сегодня дата обнуления, обнуляем недельную статистику, и расчитываем след дату обнуления
// //////////////////////////////////////////////////////////////////////////
if ($today >= $nextMonday) {
$nextMonday = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + 32));
// обнуляем посещения за прошедшую неделю
@mysql_query("DELETE FROM `weeks` WHERE `next_mon` = '" . $today . "';");
@mysql_query("DELETE FROM `top_operators_stat` WHERE `next_mon` = '" . $today . "';");
// ## Удаление неактивных пользователей
$time_stamp = time ();
$week_time = 7 * 24 * 60 * 60;
$sql_result = mysql_query("SELECT `uid` FROM `users` WHERE ('" . $time_stamp . "' - `users`.`date`) > '" . $week_time . "';");
while ($result = mysql_fetch_assoc($sql_result)) {
$del_uid = $result['uid'];
@mysql_query("DELETE FROM `users` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `count_24` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `hits_ip` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `hits_time` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `months` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `online_ip` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `top_operators_stat` WHERE `uid` = '" . $del_uid . "';");
@mysql_query("DELETE FROM `weeks` WHERE `uid` = " . $del_uid . "");
}
}
// ///////////////////////////////////////////////////////////////////
// получаем данные за текущий день недели
// Получаем хосты и хиты за текущий день
$result = mysql_query("SELECT `count`,`host` FROM `weeks` WHERE `date`='" . $today . "' AND `day_week`='" . $week_day . "' AND `uid`='" . $uid . "' LIMIT 1;");
$row = mysql_fetch_row($result);
// Если запись отсутствует, то создаем
if (empty($row)) {
// Получаем ИД категории
$result = mysql_query("SELECT `cat_id` FROM `users` WHERE `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
if (empty($row)) exit;
$cat_id = $row[0];
$nextMonday = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + 32));
@mysql_query("INSERT INTO weeks VALUES ('','" . $uid . "','" . $nextMonday . "','" . $today . "','" . $week_day . "','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','" . $cat_id . "');");
$week_day_count = 0;
$week_day_host = 0;
} else {
$week_day_count = $row[0];
$week_day_host = $row[1];
}
$week_day_count++;
// ======================================== хосты (оптимиз код) ===================================
// чтение текущего ip хита из базы
$result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE (`ip`='" . $ip . "' AND `ua`='" . $ua . "') AND `uid`='" . $uid . "';");
$row = mysql_fetch_row($result);
// если адрес отсутствует, плюсуем хост
if (empty($row)) {
// защита от накрутки
$result = mysql_query("SELECT `ip` FROM `hits_ip` WHERE `uid`='" . $uid . "' ORDER BY `time` DESC LIMIT 1;");
$row = mysql_fetch_array($result);
if (empty($row) || ($row['ip'] != $ip)) {
$hour_host++;
$week_day_host++;
$this_month_host++;
mysql_query("INSERT INTO `hits_ip` VALUES ('" . $uid . "','" . $ip . "','" . $ua . "','" . time() . "');");
}
}
// сохранение посещения
@mysql_query("UPDATE `count_24` SET `count`='" . $hour_count . "',`host`='" . $hour_host . "' WHERE `hour`='" . $hour . "' AND `date`='" . $today . "' AND `uid`='" . $uid . "';");
@mysql_query("UPDATE `weeks` SET `count`='" . $week_day_count . "',`host`='" . $week_day_host . "' WHERE `date`='" . $today . "' AND `day_week`='" . $week_day . "' AND `uid`='" . $uid . "' LIMIT 1;");
$today = date("Ym");
@mysql_query("UPDATE `months` SET `count`='" . $this_month_count . "',`host`='" . $this_month_host . "' WHERE `date`='" . $today . "' AND `uid`='" . $uid . "';");
// за сегодня
$count_today = $week_day_count;
$host_today = $week_day_host;
// ------------------------------- онлайн -----------------------------
// $today = date("Ymd");
// $now=date("ymdHi");
// удаляем записи ip старее online_time минут
// del_time время позднее которого записи считаются старыми
// $del_time = date("ymdHi", mktime(date("H"), date("i")-$online_time));
// @mysql_query("DELETE FROM `online_ip` WHERE `uid`='".$uid."' AND `time` <= '".$del_time."';");
// за 24 часа
// $today = date("Ymd");
// $hour = date("H");
// $result = mysql_query("SELECT sum(`count`) FROM `count_24` WHERE ((`date`='".$today."'-1 AND `hour`>'".$hour."') OR (`date`='".$today."' AND `hour`<='".$hour."')) AND `uid`='".$uid."';");
// $row = mysql_fetch_row($result);
// $count_24 = (int)$row[0];
// -----------------------Всего---------------------------
// $result = mysql_query("SELECT sum(`count`) FROM `months` WHERE `uid`='".$uid."';");
// $row=mysql_fetch_row($result);
// $all_count = (int)$row[0];
/*---------------
$count_today - хиты
$host_today - хосты
$online - онлайн
$count_24 - за 24 часа
$all_count - всего
-----------------*/
// вывод информации
// Получаем вид счетчика
$result = mysql_query("SELECT `type` FROM `users` WHERE `uid`='" . $uid . "';");
$type = mysql_fetch_row($result);
$image = $type[0];
$image = chunk_split ($image, 1, '.');
$image = explode(".", $image);
$image = $image[0];
if (empty($image)) $image = 1;
if ($image >= 1 && $image <= 7) {
$img = @imageCreateFromGIF("./img/" . $image . ".gif");
} else {
$img = @imageCreateFromGIF("./img/errors.gif");
}
// маленький 1
if ($image == 1) {
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3)-36;
imageString($img, 1, $x1, 15, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2, 15, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 2
if ($image == 2) {
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3)-36;
imageString($img, 1, $x1, 15, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2, 15, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 3
if ($image == 3) {
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3)-36;
imageString($img, 1, $x1, 15, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2, 15, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 4
if ($image == 4) {
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3)-36;
imageString($img, 1, $x1, 15, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2, 15, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 5
if ($image == 5) {
// $img5 = @imageCreateFromGIF ("./img/5.gif");
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3)-36;
imageString($img, 1, $x1, 15, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2, 15, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 6
if ($image == 6) {
// $color = imagecolorallocate($img, 176,176,19);
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3);
$y = 3;
imageString($img, 1, $x1, $y + 12, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2-36, $y + 12, $host_today, imagecolorallocate($img, 255, 255, 255));
}
// маленький 7
if ($image == 7) {
// $color = imagecolorallocate($img, 104,104,104);
$x1 = (ImageSX($img) - 5 * strlen($count_today)-3);
$x2 = (ImageSX($img) - 5 * strlen($host_today)-3);
$y = 3;
imageString($img, 1, $x1, $y + 12, $count_today, imagecolorallocate($img, 255, 255, 255));
imageString($img, 1, $x2-36, $y + 12, $host_today, imagecolorallocate($img, 255, 255, 255));
}
Header("Content-type: image/gif");
ImageGIF($img);
ImageDestroy($img);
/*
$reza = mysql_query ("SELECT * FROM `gener`");
if (mysql_affected_rows()==0){
$ins_str = "INSERT INTO `gener` SET `time`='0'";
if (mysql_query ($ins_str)) {
$ttttt=0;
} else {
$msg = " ".mysql_error()." ";
}
}
else{$raw = mysql_fetch_array ($reza);
$ttttt = $raw["time"];
}
list($msec,$sec)=explode(chr(32),microtime());
$sekunda= round(($sec+$msec)-$HeadTime,4);
$sekunda = round(($ttttt+$sekunda)/2,4);
mysql_query ("UPDATE `gener` SET `time`='".$sekunda."'");
*/
?>