Home >Backend Development >PHP Tutorial >php counter program

php counter program

高洛峰
高洛峰Original
2016-12-02 11:41:231395browse

1) Text counter
$countfile="/count.txt"; //Set the file to save the data
if (!file_exists($countfile)){// Determine whether the file exists
exec( "echo 0 > $countfile");
}
$fp = fopen($countfile,"rw");
$length=filesize($countfile);
$num = fgets($ fp,$length);
$num += 1;
exec( "rm -rf $countfile");
exec( "echo $num > $countfile");
print "Total visits:"."$ num"."person times"; //Show the number of visits
?>
2) Graphic counter
$countfile="/count-num.txt"; //Set the file to save the data
if (!file_exists ($countfile)) //Determine whether the file exists
{exec( "echo 0 > $countfile");}
$fp = fopen($countfile,"rw");
$length=filesize($countfile);
$num = fgets($fp,$length);
$num += 1;
exec( "rm -rf $countfile");
exec( "echo $num > $countfile");
$len_str = strlen($num);
for($i=0;$i<$len_str;$i++){
$each_num = substr($num,$i,1);
$out_str = $out_str . "";
}
print "Total visits:"."$out_str"."Persons"; //Display the number of visits
?>

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