<?
/* Anbieter: http://www.vonderborn.com Autor: Philipp von der Born */
$expire = 1;
$filename = "counter.txt"; # ścieżka dostępu do pliku tekstowego przechowującego
dane do statystyki
if (file_exists($filename))
{
$c_file = file($filename);
$ignore = false;
$current_agent = (isset($_SERVER['HTTP_USER_AGENT'])) ?
addslashes(trim($_SERVER['HTTP_USER_AGENT'])) : "no agent";
$current_time = time();
$current_ip = $_SERVER['REMOTE_ADDR'];
if (substr_count($current_agent, "bot") > 0)
$ignore = true;
if ($c_file == FALSE)
$ignore = true;
for ($i = 1; $i < sizeof($c_file); $i++)
{
list($counter_ip, $counter_time) = explode("||", $c_file[$i]);
$counter_time = trim($counter_time);
if ($counter_ip == $current_ip && $current_time-$expire < $counter_time)
{
$ignore = true;
break;
}
}
if ($ignore == false)
{
if (sizeof($c_file) == 0)
{
$add_line1 = date("z") . ":1||" . date("W") . ":1||" . date("n") . ":1||" .
date("Y") . ":1||1||1||" . $current_time . "\n";
$add_line2 = $current_ip . "||" . $current_time . "\n";
$fp = fopen($filename,"w+");
if ($fp)
{
flock($fp, LOCK_EX);
fwrite($fp, $add_line1);
fwrite($fp, $add_line2);
flock($fp, LOCK_UN);
fclose($fp);
}
$day = $week = $month = $year = $all = $record = 1;
$record_time = $current_time;
$online = 1;
}
else
{
list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) =
explode("||", $c_file[0]);
$day_data = explode(":", $day_arr);
$day = $day_data[1];
if ($day_data[0] == date("z")) $day++; else $day = 1;
$week_data = explode(":", $week_arr);
$week = $week_data[1];
if ($week_data[0] == date("W")) $week++; else $week = 1;
$month_data = explode(":", $month_arr);
$month = $month_data[1];
if ($month_data[0] == date("n")) $month++; else $month = 1;
// year
$year_data = explode(":", $year_arr);
$year = $year_data[1];
if ($year_data[0] == date("Y")) $year++; else $year = 1;
$all++;
$record_time = trim($record_time);
if ($day > $record)
{
$record = $day;
$record_time = $current_time;
}
$online = 1;
$fp = fopen($filename,"w+");
if ($fp)
{
flock($fp, LOCK_EX);
$add_line1 = date("z") . ":" . $day . "||" . date("W") . ":" . $week . "||" .
date("n") . ":" . $month . "||" . date("Y") . ":" . $year . "||" . $all . "||" .
$record . "||" . $record_time . "\n";
fwrite($fp, $add_line1);
for ($i = 1; $i < sizeof($c_file); $i++)
{
list($counter_ip, $counter_time) = explode("||", $c_file[$i]);
if ($current_time-$expire < $counter_time)
{
$counter_time = trim($counter_time);
$add_line = $counter_ip . "||" . $counter_time . "\n";
fwrite($fp, $add_line);
$online++;
}
}
$add_line = $current_ip . "||" . $current_time . "\n";
fwrite($fp, $add_line);
flock($fp, LOCK_UN);
fclose($fp);
}
}
}
else
{
if (sizeof($c_file) > 0)
list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) =
explode("||", $c_file[0]);
else
list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) =
explode("||", date("z") . ":1||" . date("W") . ":1||" . date("n") . ":1||" .
date("Y") . ":1||1||1||" . $current_time);
$day_data = explode(":", $day_arr);
$day = $day_data[1];
$week_data = explode(":", $week_arr);
$week = $week_data[1];
$month_data = explode(":", $month_arr);
$month = $month_data[1];
$year_data = explode(":", $year_arr);
$year = $year_data[1];
$record_time = trim($record_time);
$online = sizeof($c_file) - 1;
}
?>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" bordercolor="#111111" width="200">
<tr>
<td width="200" align="left" colspan="3">
<font face="Arial, Helvetica, sans-serif" size="1" color="003300">
<a href="http://www.vonderborn.com" target="_blank">
<img src="counter.gif" width="16" height="16" border="0" />
</a> Statystyka odwiedzin witryny</font></tr>
<tr>
<td width="103" align="left">
<font size="1" face="Tahoma" color="#FFFFFF">W tej chwili </font>
</td>
<td width="39" align="center">
<font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"> » »
»
</td>
<td width="58" align="right">
<font size="1" face="Tahoma" color="#FFFFFF"> <? echo $online; ?> </font>
</td>
</tr>
<tr>
<td width="103" align="left"> <font size="1" face="Tahoma" color="#003300">Dzisiejszego
dnia </font></td>
<td width="39" align="center"> <font face="Arial, Helvetica, sans-serif" size="1"
color="003300"> » » »</td>
<td width="58" align="right"> <font size="1" face="Tahoma" color="#003300"><?
echo $day; ?> </font></td>
</tr>
<tr>
<td width="103" align="left"> <font size="1" face="Tahoma" color="#003300">W tym
tygodniu </font></td>
<td width="39" align="center"> <font face="Arial, Helvetica, sans-serif" size="1"
color="003300"> » » »</td>
<td width="58" align="right"> <font size="1" face="Tahoma" color="#003300"><?
echo $week; ?> </font></td>
</tr>
<tr>
<td width="103" align="left"> <font size="1" face="Tahoma" color="#003300">W tym
miesiącu </font></td>
<td width="39" align="center"> <font face="Arial, Helvetica, sans-serif" size="1"
color="003300"> » » »</td>
<td width="58" align="right"> <font size="1" face="Tahoma" color="#003300"> <?
echo $month; ?> </font></td>
</tr>
<tr>
<td width="103" align="left"> <font size="1" face="Tahoma" color="#003300">W tym
roku </font></td>
<td width="39" align="center"> <font face="Arial, Helvetica, sans-serif" size="1"
color="003300"> » » »</td>
<td width="58" align="right"> <font size="1" face="Tahoma" color="#003300"><?
echo $year; ?> </font></td>
</tr>
<tr>
<td width="103" align="left"> <font size="1" face="Tahoma" color="#003300">W
sumie </font></td>
<td width="39" align="center"> <font face="Arial, Helvetica, sans-serif" size="1"
color="003300"> » » »</td>
<td width="58" align="right"> <font size="1" face="Tahoma" color="#003300"><?
echo $all; ?> </font></td>
</tr>
<tr>
<td width="200" align="left" colspan="3"><font size="1"> </font></td>
</tr>
<tr>
<td width="200" align="left" colspan="3" align = "center">
<font size="1" face="Tahoma" color="#003300">
<? echo date("Y.m.d", $record_time) ?> odwiedziło nas <? echo $record; ?>
Internautów
</td>
</tr>
<tr>
<td width="200" align="left" colspan="3"> </td>
</tr>
<tr>
<font size="1" face="Tahoma" color="#003300">
<td width="200" align="left" colspan="3" align = "center">
<p align="center">
<input type="button" value="Odśwież stronę" onClick="window.location.reload()"
style="font-size: 10px; font-family: Tahoma; width: 190">
</td>
</tr>
</table>
<?
}
?>
Pokaż / ukryj skrypt