View Single Post
Old 01-16-2005, 09:28 AM  
celebx
Confirmed User
 
Join Date: Jul 2001
Location: The Netherlands
Posts: 197
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_return9); 
    } 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
__________________
Message me for more info: ICQ 8322641 (@gmail.com).

Last edited by celebx; 01-16-2005 at 09:30 AM..
celebx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote