shell> cd [The directory of your PHP file.] shell> touch counter.txt shell> chmod 666 counter.txtThese are the NetCloak Counter commands.
This page has been accessed
<?php InsertCount("counter.txt"); ?> times.
The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// InsertCount($file,$increment)
// - - - - - - - - - - - - - - -
// Increments the count by 1 in the file $counter
// unless $increment is false.
// Prints the counter value.
//
// PHP Example:
//
// echo 'The page has been accessed ';
// InsertCount("counter.txt");
// echo ' times.';
//
// See: GetCount()
//-----------------------------------------------------
function InsertCount( $file, $increment = true )
{
print GetCount( $file, $increment );
}
?>
|
The counter reads <?php InsertCount("counter.txt",false); ?>.
The file must already be created with rw access to the user nobody.
See: InsertCount()
<?php Count("counter.txt"); ?>
The counter has been incremented.
The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// GetCount($file,$increment)
// - - - - - - - - - - - -
// Increments the count by 1 in the file $counter
// unless $increment is false.
// Returns the counter value.
//
// PHP Example:
//
// $count = Count("counter.txt");
// if( $count < 50 )
// print "You are a visiting a new page.";
// else
// print "You are visitor #$count.";
//-----------------------------------------------------
function GetCount( $file, $increment = true )
{
if( !($fp = fopen( $file, "r" )) )
{
print "\nError reading counter file: $file.\n";
$count = 0;
}
else
{
$count = strtok(fgets($fp,80), " ");
$time = strtok(" ");
fclose($fp);
}
if( !$increment )
return $count;
$count++;
if( !$time )
$time = time();
if( !($fp = fopen( $file, "w" )) )
{
print "\nError writing counter file: $file.\n";
}
else
{
fwrite($fp, sprintf( "%d %d", $count, $time ));
fclose($fp);
}
return $count;
}
?>
|
<?php ShowCount(0,50,"counter.txt"); ?> Only the first 50 visitors get to see this. <?php } ?>The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// ShowCount($lowvalue,$highvalue,$file)
// - - - - - - - - - - - - - - - - - - - -
// Returns true if the counter value is between
// $lowvalue and $highvalue.
//
// See: GetCount()
//-----------------------------------------------------
function ShowCount($lowvalue,$highvalue,$file)
{
$count = GetCount($file,false);
return ($lowvalue <= $count && $count <= $highvalue);
}
?>
|
<?php if( HideCount(0,200,"counter.txt") ) { ?>
The first 200 visitors do not see this.
<?php } ?>
The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// HideCount($lowvalue,$highvalue,$file)
// - - - - - - - - - - - - - - - - - - - -
// Returns false if the counter value is between
// $lowvalue and $highvalue.
//
// See: Count()
//-----------------------------------------------------
function HideCount($lowvalue,$highvalue,$file)
{
$count = Count($file,false);
return ($count > $highvalue || $lowvalue > $count);
}
?>
|
The counter was created on
<?php InsertCounterDate("counter.txt"); ?>.
The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// InsertCounterDate($file,$offset,$format)
// - - - - - - - - - - - - - - - - - - - -
// Prints the date the counter was created.
//
// See: GetCounterTime()
//-----------------------------------------------------
function InsertCounterDate($file, $offset=0, $format="long")
{
$kHour = 60*60;
$time = GetCounterTime($file);
if( strcasecmp($format,"long") )
print date("l, F j, Y",$time+$offset*$kHour);
else
print date("m/d/y" ,$time+$offset*$kHour);
}
?>
|
<?php
//-----------------------------------------------------
// GetCounterTime($file)
// - - - - - - - - - - - - - - - - - - - -
// Returns the UNIX timestamp for when the counter file
// was created.
//
// On error, returns "" or 0.
//-----------------------------------------------------
function GetCounterTime($file)
{
if( !($fp = fopen( $file, "r" )) )
{
print "\nError reading counter file: $file.\n";
$count = 0;
}
else
{
$count = strtok(fgets($fp,80), " ");
$time = strtok(" ");
fclose($fp);
}
return $time;
}
?>
|
The counter was created at
<?php InsertCounterTime("counter.txt"); ?>.
The file must already be created with rw access to the user nobody.
<?php
//-----------------------------------------------------
// InsertCounterTime($file,$offset,$format)
// - - - - - - - - - - - - - - - - - - - -
// Prints the time of day the counter was created.
//
// See: GetCounterTime()
//-----------------------------------------------------
function InsertCounterTime($file, $offset=0, $format="long")
{
$kHour = 60*60;
$time = GetCounterTime($file);
if( strcasecmp($format,"long") )
print date("g:i:s A",$time+$offset*$kHour);
else
print date("g:i A" ,$time+$offset*$kHour);
}
?>
|