Simple Counter
/*
|| A simple counter
*/
function get_hitcount($counter_file)
{
/* Reset counter to zero
This way if the counter has not been used yet, the initial value will be 1
Of course you can also set the initial value to 20,000 to trick people
*/
$count=0;
// If the file storing the counter already exists, read its contents
if ( file_exists($counter_file) )
{
$fp=fopen($counter_file,"r");
// We only picked the top 20, I hope your site won’t be too popular
$count=intval( fgets($fp,20));
// Since the function fgets() returns a string, we can automatically convert it to an integer by adding 0
fclose($fp);
//Complete file operation
}
// Increment the count value
$count ;
//Write new count value to file
$fp=fopen($counter_file,"w");
fputs($fp,$count);
fclose($fp);
# Return count value
return ($count);
}
?>
http://www.bkjia.com/PHPjc/631904.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631904.htmlTechArticleSimple counter? /* || A simple counter*/ function get_hitcount($counter_file) { /* Convert the counter Reset to zero so that if the counter has not been used, the initial value will be 1. You can of course...