<html>
<head>
<title> php tutorial to write the page counter code </ title>
<head>
<body>
<? php
$ countfile = "counter.txt";
// Define the counter to write the file is the counter.txt file in the current directory, and then we should test whether the file can be opened
if (($ fp = fopen ($ countfile, "r +")) == false) {
// Open the 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, it is assumed to be 1
$ count = fread ($ fp, 10);
// Read 10-bit data
$ count = $ count + 1;
// count ++
fclose ($ fp);
// Close the current file
$ fp = fopen ($ countfile, "w +");
// Open the file in overwrite mode
fwrite ($ fp, $ count);
// write new data after adding 1
fputs ($ fp, $ fg);
// Display the count result
// Digital Display
echo "<div align = center> <font size = 5> count: $ count </ font> <br>";
// graphics mode count
$ fp = fopen ($ countfile, "r"); // Open the file in read-only mode
$ array_count = 1; / / Define a variable that represents the position of the array element, the following use
while (! feof ($ fp)) {
$ current_number = fgetc ($ fp);
$ counter_array [$ array_count] = $ current_number;
$ array_elements = count ($ counter_array);
$ array_count = $ array_count + 1;
}
echo "<div align = center> <font size = 5> count:";
for ($ array_id = 1; $ array_id <$ array_elements; ++ $ array_id) {
echo "<img src = countimg /". $ counter_array [$ array_id]. ". gif>";
}
echo "</ font>";
fclose ($ fp);
// And close the file
}
?>
</ body>
</ html>