Describes how to add a counter in PHP. When we set up a website, some webmasters will need to add counters on their home pages. today we will introduce the following code to counter. inc :? * | When we build a website, some webmasters may need to add counters on their home pages. today we will talk about it in detail.Counter. inc contains the following code:
-
- /*
- | A simple counter
- */
- Function get_hitcount ($ counter_file)
- {
- /* Returns the counter to zero.
- In this case, if the counter is not used, the initial value is 1.
- Of course, you can set the initial value to 20000 to cheat me.
- */
- $Count=0;
- // If the stored counter file already exists, read the content
- If (file_exists ($ counter_file ))
- {
- $Fp=Fopen($ Counter_file, "r ");
- // We only took the first 20 digits. I hope your site will not be too popular.
- $Count=0+ Fgets ($ fp, 20 );
- // Because the function fgets () returns a string, we can automatically convert it to an integer by adding 0.
- Fclose ($ fp );
- // File operation completed
- }
- // Increase the count value once
- $ Count ++;
- // Write the new count value to the file
- $Fp=Fopen($ Counter_file, "w ");
- Fputs ($ fp, $ count );
- Fclose ($ fp );
- # Return count value
- Return ($ count );
- }
- ?>
After adding a counter in PHP, we need to change the front. php3 file to display this counter:
-
- Include("Include/counter. inc ");
- // I put the counter value in the counter.txt file, read and output
- Printf ("<CENTER><B>% 06d B> CENTER> <BR>N ",
- Get_hitcount ("counter.txt "));
- Include ("include/footer. inc ");
- ?>
All the above code is the PHP counter adding implementation method, hope to have some help to friends in need.
Counter. inc contains the following code :? /* | A simple...