session_start();
$file_name = "counter";
$h = count( $file_name )-1;
$hitfile = "./sb_counter/".$file_name.".txt";
## txt where the hits are stored
if ( !file_exists( $hitfile ) ) {
print "The file $hitfile does not exists ...";
if ( touch ( $hitfile ) ) {
print "The $hitfile was be created!";
}
else {
print "Can't be create $hitfile! ... exitting now --";
exit;
}
}
$fp = fopen( $hitfile,"r+" ); ## file pointer
$hits=fread( $fp,filesize( $hitfile ) );
## If you use more then one page with this counter, change the session variable to unique name in every one.
if( !session_is_registered( "counter" ) ) { ## if the session variable don't be yet
fseek( $fp,0 );
ftruncate( $fp,0 ); ## clear the file out
$hits++;
fwrite( $fp,$hits );
session_register( "counter" );
}
fclose( $fp );
## The graphical counter -------------
$ghtis = $hits;
$garray = array();
while ( $ghtis ){
$flt = $ghtis%10;
$int = sprintf( "%d", $ghtis/10 );
array_push( $garray,"$flt" );
$ghtis = $int;
}
if ( count( $garray ) < 5 ) {
$c = 5-count( $garray );
for( $i=0;$i<$c;$i++ ) {
array_push( $garray,"0" );
}
}
## End of graphical counter part ----
?>
Untitled Document
www.krisztamasszazs.hu