We want to provide the following PHP tutorial flow Statistics Code is the basic text file without a database tutorial, below we start from simple to complex page access count counter code instance.
The code is as follows |
Copy Code |
<HTML> <HEAD> <TITLE> file System-based page Counter example </TITLE> </HEAD> <BODY> ? Php $countfile = "Num.txt"; Defines that the file written by the counter is count.txt under the current directory, and then we should test whether the file can be opened if ($fp = fopen ($countfile, "r+")) = = False) {//Open file in read-write mode, exit if not open printf ("Open file%s failed!", $countfile); Exit } Else { If the file can be opened normally, read the data in the file, assuming it is 1 $count = Fread ($fp, 10); Read 10-bit data $count = $count + 1; Fclose ($FP); Close the current file $fp = fopen ($countfile, "w+"); Open files in overwrite mode Fwrite ($fp, $count); Write new data after add 1 Fclose ($FP); and close the file Echo ' Hello, you are the first '. $count. ' Visitors '; } ?> </BODY> </HTML> Counter two, this base database <HTML> <HEAD> <TITLE> Database-based page Counter example </TITLE> </HEAD> <BODY> |