Показать сообщение отдельно

  #480  
Старый 04.11.2008, 14:57
heretic1990
Постоянный
Регистрация: 02.07.2008
Сообщений: 472
С нами: 9399011

Репутация: 444
Talking

Скрипт считает, сколько было показано страниц всего, сколько показано сегодня, сколько посетителей было всего, сколько было сегодня, сколько находится на сайте сейчас.

Установка

1.
Закачайте файлы на сервер в любую папку.
2. Установите следующие права доступа:
на саму папку - 711 (или 755)
на файл counter.php - 444 (или 644)
на файлы .dat - 600 (или 666)
3. Вставьте на страницу следующий код:
Код HTML:
<script language="JavaScript" src="http://you_url/you_dir/counter.php"></script>


PHP код:
<?php
$total_data
="base.dat";
$online_data="online.dat";
$time=time();
$now=(int)(time()/86400);
$past_time=time()-600;

$readdata=fopen($online_data,"r") or die("Не могу открыть файл $online_data");
$online_data_array=file($online_data);
fclose($readdata);

if(
getenv('HTTP_X_FORWARDED_FOR'))
        
$user=getenv('HTTP_X_FORWARDED_FOR');
else
        
$user=getenv('REMOTE_ADDR');

$d=count($online_data_array);
for(
$i=0;$i<$d;$i++)
        {
        list(
$live_user,$last_time)=explode("::","$online_data_array[$i]");
        if(
$live_user!=""&&$last_time!=""):
        if(
$last_time<$past_time):
                
$live_user="";
                
$last_time="";
        endif;
        if(
$live_user!=""&&$last_time!="")
                {
                if(
$user==$live_user)
                        {
                        
$online_array[]="$user::$time\r\n";
                        }
                else
                        
$online_array[]="$live_user::$last_time";
                }
        endif;
        }

        if(isset(
$online_array)):
        foreach(
$online_array as $i=>$str)
                {
                if(
$str=="$user::$time\r\n")
                        {
                        
$ok=$i;
                        break;
                        }
                }
        foreach(
$online_array as $j=>$str)
                {
                if(
$ok==$j) { $online_array[$ok]="$user::$time\r\n"; break;}
                }
       endif;

$writedata=fopen($online_data,"w") or die("Не могу открыть файл $online_data");
flock($writedata,2);
if(
$online_array==""$online_array[]="$user::$time\r\n";
foreach(
$online_array as $str)
        
fputs($writedata,"$str");
flock($writedata,3);
fclose($writedata);

$readdata=fopen($online_data,"r") or die("Не могу открыть файл $online_data");
$online_data_array=file($online_data);
fclose($readdata);
$online=count($online_data_array);

$f=fopen($total_data,"a");
$call="$user|$now\n";
$call_size=strlen($call);
flock($f,2);
fputs($f$call,$call_size);
flock($f,3);
fclose($f);

$tarray=file($total_data);
$total_hits=count($tarray);

$today_hits_array=array();
for(
$i=0;$i<count($tarray);$i++)
        {
        list(
$ip,$t)=explode("|",$tarray[$i]);
        if(
$now==$t) { array_push($today_hits_array,$ip); }
        }
$today_hits=count($today_hits_array);

$total_hosts_array=array();
for(
$i=0;$i<count($tarray);$i++)
        {
        list(
$ip,$t)=explode("|",$tarray[$i]);
        
array_push($total_hosts_array,$ip);
        }
$total_hosts=count(array_unique($total_hosts_array));

$today_hosts_array=array();
for(
$i=0;$i<count($tarray);$i++)
        {
        list(
$ip,$t)=explode("|",$tarray[$i]);
        if(
$now==$t) { array_push($today_hosts_array,$ip); }
        }
$today_hosts=count(array_unique($today_hosts_array));

echo 
"document.write('<table bgcolor=#888888 cellspacing=1 cellpadding=1 style=\"font-family:Verdana;font-size:10px;\">');";
echo 
"document.write('<tr><td bgcolor=#CCCCFF align=center>Статистика сайта</td></tr>');";
echo 
"document.write('<tr><td bgcolor=#E8E8FF>Хитов всего: $total_hits</td></tr>');";
echo 
"document.write('<tr><td bgcolor=#E8E8FF>Хитов сегодня: $today_hits</td></tr>');";
echo 
"document.write('<tr><td bgcolor=#E8E8FF>Хостов всего: $total_hosts</td></tr>');";
echo 
"document.write('<tr><td bgcolor=#E8E8FF>Хостов сегодня: $today_hosts</td></tr>');";
echo 
"document.write('<tr><td bgcolor=#E8E8FF>Сейчас на сайте: $online</td></tr>');";

?>
и два пустых файла:
base.dat
online.dat
 
Ответить с цитированием