Здравствуйте,
Написал счетчик для уникальных посетителей за день по utm, но он заносит заносит в базу неверную информацию, т.е. по ссылкам пришло 566 пользователей, а базу занеслось 61, остальные ушли в незарегистрированные. В чем проблема? Может, ошибка в проверке даты?
$cookie_days = 30;
$cookie_timestamp = strtotime('+' . $cookie_days . ' days');
if (isset($_GET['ref']) && !empty($_GET['ref'])) {
setcookie('utm_source', $_GET['ref'], $cookie_timestamp, '/');
setcookie('ref', $_GET['ref'], $cookie_timestamp, '/');
setcookie('userh', '', time()-3600);
header('Location: /');
}
if (isset($_GET['utm_source']) && !empty($_GET['utm_source'])) {
setcookie('utm_source', $_GET['utm_source'], $cookie_timestamp, '/');
setcookie('ref', $_GET['utm_source'], $cookie_timestamp, '/');
setcookie('userh', '', time()-3600);
header('Location: /');
}
if (!isset($_COOKIE['userh'])) {
setcookie('userh', 'cxv', time() + 86400);
if (isset($_COOKIE['utm_source'])) {
$ress = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as total FROM `utm_counter` WHERE `fromutm` ='" . $_COOKIE['utm_source']."' AND `datetime` = CURDATE()"));
if ($ress['total'] == '0') {
mysql_query("INSERT INTO `utm_counter` (`count`,`fromutm`,datetime) VALUES ('1','" . $_COOKIE['utm_source'] . "',CURDATE())");
} else {
$counter = mysql_fetch_assoc(mysql_query("SELECT count as total FROM `utm_counter` WHERE `fromutm` ='" . $_COOKIE['utm_source']."' AND `datetime` = CURDATE()"));
$counters = $counter['total'] + 1;
mysql_query("UPDATE `utm_counter` SET `count`=" . $counters . " WHERE `fromutm` ='" . $_COOKIE['utm_source']."' AND `datetime` = CURDATE()");
}
} else {
$ress = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as total FROM `utm_counter` WHERE `datetime` >= CURDATE() AND `fromutm` = 'without utm'"));
if ($ress['total'] == '0') {
mysql_query("INSERT INTO `utm_counter` (`count`,`fromutm`,datetime) VALUES ('1','without utm',CURDATE())");
} else {
$counter = mysql_fetch_assoc(mysql_query("SELECT count as total FROM `utm_counter` WHERE `datetime` >= CURDATE() AND `fromutm` = 'without utm'"));
$counters = $counter['total'] + 1;
mysql_query("UPDATE `utm_counter` SET `count`=" . $counters . " WHERE `datetime` >= CURDATE() AND `fromutm` ='without utm'");
}
}
}