Ein simpler, dateibasierter Counter.
<?php
/*
Ein Counter
Aktion: PHP Scripte für die armen dieser Welt
Der Erlös geht für mein Pausenbrot drauf
Copyright (c) 2004 by Phillip 'Firebird' Berndt
*/
$serialized_counterData = '';
$counterData = unserialize($serialized_counterData);
// Online schalten
if($counterData['currDay'] != date('d-m-Y'))
{
$counterData['yesterDay'] = $counterData['currDay'];
$counterData['currDay'] = date('d-m-Y');
$counterData['toDay'] = 0;
}
if(!isset($counterData['whoIsOnline'][$_SERVER['REMOTE_ADDR']]))
{
$counterData['visits']++;
$counterData['toDay']++;
}
$counterData['hits']++;
$counterData['whoIsOnline'][$_SERVER['REMOTE_ADDR']] = time();
// Alte User löschen
foreach($counterData['whoIsOnline'] as $key => $time)
if($time + 500 < time()) unset($counterData['whoIsOnline']);
// Speichern
$myData = file_get_contents(__FILE__);
$myData = preg_replace('/\$serialized_counterData = \'.*\';/siU',
'$serialized_counterData = \''.serialize($counterData).'\';', $myData);
$myFile = fopen(__FILE__, 'wb');
fwrite($myFile, $myData);
fclose($myFile);
// Ausgeben
echo('Hits: '.$counterData['hits'].'<br />');
echo('Besucher: '.$counterData['visits'].'<br />');
echo('Gestern: '.$counterData['yesterDay'].'<br />');
echo('Heute: '.$counterData['toDay'].'<br />');
echo('Online: '.count($counterData['whoIsOnline']).'<br />');
?>