Home >Backend Development >PHP Tutorial >Simple counter_PHP tutorial

Simple counter_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:59:22791browse

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);
}
?>

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn