File size: 2.67Kb
<?
include 'config.php'; # встовляем конфиг базы данных
###########################################
#################################Счетчик IP
$bro = $HTTP_USER_AGENT;
$date = date('Y-m-d H:i:s');
$page = $PHP_SELF;
$ip = $REMOTE_ADDR;
$forw = getenv(HTTP_X_FORWARDED_FOR);
if (($forw != "") && ($forw != $REMOTE_ADDR)) $ip = $ip.'/'.$forw;
### Счетчик ip
$query = "INSERT INTO `ip` ( `id_ip` , `ip` , `page`, `date` ) VALUES ('', '".$ip."', '".$PHP_SELF."', '".$date."');";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
$ra = mysql_fetch_array($result);
if (!$ra) echo mysql_error();
#########################################
################################Счетчик Host
$query = "SELECT count(*) FROM host WHERE 1 AND ip_host = '".$ip."';";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
$ra = mysql_fetch_array($result);
if (!$ra) echo mysql_error();
$answer = $ra ['count(*)'];
if (!$answer) echo mysql_error();
if ($answer != 1)
{
$query = "INSERT INTO `host` ( `id_host` , `ip_host` , `page` ) VALUES ('', '".$ip."', '".$PHP_SELF."');";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
}
#########################################
######################### Счетчик страниц
$query = "SELECT count(*) FROM page WHERE 1 AND page = '".$PHP_SELF."';";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
$ra = mysql_fetch_array($result);
if (!$ra) echo mysql_error();
$answer = $ra ['count(*)'];
if (!$answer) echo mysql_error();
if ($answer != 1)
{
$query = "INSERT INTO `page` ( `id_page` , `page` , `count` ) VALUES ('', '".$PHP_SELF."', '1');";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
}
else
{
###
$query = "SELECT * FROM page WHERE 1 AND page = '".$PHP_SELF."' ;";
$result = mysql_query($query);
$otvet = mysql_fetch_array($result);
$new_count = $otvet ['count'] + 1;
$id = $otvet ['id_page'] ;
###
$query = "UPDATE `page` SET `count` = '".$new_count."' WHERE `id_page` = '".$id."' AND `page` = '".$PHP_SELF."' LIMIT 1 ;";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
}
#########################################
### Счетчик bro
$query = "INSERT INTO `browser` ( `id` , `br` , `ip`, `page`, `date` ) VALUES ('', '".$bro."', '".$ip."', '".$PHP_SELF."', '".$date."');";
if (!$query) echo mysql_error();
$result = mysql_query($query);
if (!$result) echo mysql_error();
$ra = mysql_fetch_array($result);
if (!$ra) echo mysql_error();
?>