This article mainly introduces the use of text statistical access to PHP methods, involving the PHP text file reading and writing and numerical operation of the relevant skills, the need for friends can refer to the next
Method 1:
$fp = fopen ("Counter.txt", "r+"), while (!flock ($FP, LOCK_EX)) {//acquire a exclusive LOCK //Waiting to LOCK the FIL e} $counter = Intval (Fread ($fp, FileSize ("Counter.txt")), $counter ++;ftruncate ($fp, 0); Truncate Filefwrite ($FP, $counter); Set your Datafflush ($FP); Flush output before releasing the Lockflock ($FP, lock_un); Release the Lockfclose ($FP);
Method 2:
counter.php file:
<?php/* counter *///opens countlog.txt to read the number of Hits$datei = fopen ("Countlog.txt", "R"); $count = Fgets ($dat ei,1000); fclose ($datei); $count = $count + 1; echo "$count"; echo "hits"; echo "\ n";//opens Countlog.txt to change new hit Number$datei = fopen ("Countlog.txt", "w"); Fwrite ($datei, $count); fclose ($datei);? >
Usage:
<?phpinclude ("counter.php");? >
Summary: The above is the entire content of this article, I hope to be able to help you learn.