Create count.txt text file and index.php, prepare 1-9 altogether nine numbers of pictures, online can find this kind of picture, respectively named: 1-9
Count.txt file, save the number of visits, such as input 100
index.php:
- <?php
- Select a color to display statistics
- $color _name= "Black_white";
- $color _name= "White_black";
- $color _name= "Black_transparent";
- Open file read-only mode
- $FP =fopen ("Counter.txt", "R");
- Reading data
- $counter =fgets ($FP, 1024);
- Close File
- Fclose ($FP);
- Counter increased by 1
- $counter + +;
- Open files in writable mode
- $FP =fopen ("Counter.txt", "w");
- Write new statistics to a text file
- Fputs ($fp, $counter);
- Close File
- Fclose ($FP);
- To prevent other users from accessing the page at this time, the contents of the file have changed
- Reopen the file to read the latest statistics
- $FP =fopen ("Counter.txt", "R");
- $counter =fgets ($FP, 1024);
- Fclose ($FP);
- Loop to display statistical data in images
- Different numbers for different images
- If the number 1, then the image 1.gif to display
- for ($i =0; $i <strlen ($counter); $i + +)
- {
- $result = $counter [$i];
- Switch ($result)
- {
- Case "0": $ret [$i]= "0.gif"; Break Show a digital picture
- Case "1": $ret [$i]= "1.gif"; Break
- Case "2": $ret [$i]= "2.gif"; Break
- Case "3": $ret [$i]= "3.gif"; Break
- Case "4": $ret [$i]= "4.gif"; Break
- Case "5": $ret [$i]= "5.gif"; Break
- Case "6": $ret [$i]= "6.gif"; Break
- Case "7": $ret [$i]= "7.gif"; Break
- Case "8": $ret [$i]= "8.gif"; Break
- Case "9": $ret [$i]= "9.gif"; Break
- }
- }
- echo "The total number of visits to this page is:";
- Loop output Image
- for ($i =0; $i <sizeof ($ret); $i + +)
- echo "
- ?>