<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>";
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.