Home · PHP Scripts · text file hit counter

cms-zen dot com

online web development :: art and design :: fun stuff
best-budd
sNews Development cms road trip PHP Scripts Photoshop Guides Css Guides Music and video clips Art Gallery Low Light Photography Impression Photography

text file hit counter

This php script will count hits to page/site you define.

 
<?php

/**
 * Create an empty text file called counterlog.txt and 
 * upload to the same directory as the page you want to 
 * count hits for.
 * 
 * Add this line of code on your page:
 * <?php include "text_file_hit_counter.php"; ?>
 */

    // Open the file for reading
    
$fp fopen("counterlog.txt""r");

    
// Get the existing count
    
$count fread($fp1024);

    
// Close the file
    
fclose($fp);

    
// Add 1 to the existing count
    
$count $count 1;

    
// Display the number of hits
    // If you don't want to display it, comment out this line
    
echo "<p>Page views:" $count "</p>";

    
// Reopen the file and erase the contents
    
$fp fopen("counterlog.txt""w");

    
// Write the new count to the file
    
fwrite($fp$count);

    
// Close the file
    
fclose($fp);

?> 

06.12.2006. 13:48