View file counter.php

File size: 1.05Kb
<?php
require('includes/db.php');

$date = date('Y-m-d');
$id = (int)$_GET['id'];
$ip = $_SERVER['REMOTE_ADDR'];
// удаляем старые IP адреса
mysql_query("DELETE FROM counter_ips WHERE last_date < '$date'");

$ips = mysql_query("SELECT count(*) FROM counter_ips WHERE id = '$id' AND ip = '$ip'");
list($total_ips) = mysql_fetch_array($ips);

if($total_ips == 0)
{
   // если такого IP еще нет
   mysql_query("INSERT INTO counter_ips(id, ip, last_date) VALUES ('$id', '$ip', '$date')");

   $ips = mysql_query("SELECT count(*) FROM counter WHERE id = '$id' AND last_date = '$date'");
   list($total_ips) = mysql_fetch_array($ips);
   if($total_ips == 0)
   {
      // сегодня посещений не было, это первое
      mysql_query("UPDATE counter SET today = 1, total = total + 1, last_date = '$date' WHERE id = '$id'");
   }
   else
   {
      mysql_query("UPDATE counter SET today = today + 1, total = total + 1 WHERE id = '$id'");
   }
}
   $im = ImageCreateFromPng("counter.png");
   header("Content-type: image/vnd.wap.wbmp");
   ImageWBMP($im);

?>