PHP Code:
<?php
// SNT's Array2Txt Functions :)
function Array2Txt($array,$fill='',$tab=1,$compress=0) {
if (!$fill) {
$txt_return='array(';
}
$n=rand();
$run[$n]=0;
for($i=0;$i<$tab;$i++) {$t.="\t";}
foreach ($array as $key => $value) {
if (!$run[$n]) {
$c='';
} else {
$c=', ';
}$run[$n]++;
if (is_array($value)) {
$txt_return.=$c."\n".$t.'''.$key.'' => array('.Array2Txt($value,'',1,$tab+1);
continue 1;
}
$txt_return.=$c."\n".$t.'''.$key.'' => ''.$value.''';
}
if (!$fill) {
$txt_return.=');';
} else {
$txt_return.=')';
}
if ($compress) {
return gzcompress($txt_return, 9);
} else {
return $txt_return;
}
}
function Txt2Array($arraytxt,$decompress=0) {
if ($decompress) {
eval('$return_array = '.gzuncompress($arraytxt));
return $return_array;
} else {
eval('$return_array = '.$arraytxt);
return $return_array;
}
}
//register user and count pageviews per page
session_start();
if (!isset($_SESSION['count'])) {
$new_visitor=1;
$_SESSION['visitor'] = array();
$_SESSION['visitor'][$_SERVER["PHP_SELF"]]=1;
} else {
$_SESSION['visitor'][$_SERVER["PHP_SELF"]]++;
}
//create counter data array from counter data file
if (file_exists($counter_data_file)) {
$counter_data = Txt2Array(file_get_contents($counter_data_file));
} else { // create counter data file (if not exist)
if (!$handle = fopen($counter_data_file, 'a')) {
print "Can not create counter data file.";
exit;
}
print "<!--- New Counter Data File created on ".date("r").". ---/>";
fclose($handle);
}
$counter_data[$_SERVER["PHP_SELF"]]["views"]++;
if ($new_visitor) {
$counter_data[$_SERVER["PHP_SELF"]]["visitors"]++;
}
if (is_writable($counter_data_file)) {
if (!$handle = fopen($counter_data_file, 'a')) {
print "Can not open counter data file.";
exit;
}
$counter_data_txt = Array2Txt($counter_data);
if (!fwrite($handle, $counter_data_txt)) {
print "Can not write to counter data file.";
exit;
}
print "<!--- Successfully updated counter data file, this page has been visited ".$counter_data[$_SERVER["PHP_SELF"]]["views"]." times. ---/>";
fclose($handle);
} else {
print "The counter data file is not writeable.";
}
/*
The Array2Txt using the compression functions and a MySQL DB for data storage enables storage of detailed per visitor traffic information for 1m+/day trafficed sites! It will enable you to create the easyest and fastest accessable, processless and optimum source of traffic information.
*/
?>
p.s. this code has not been tested