Geekempire Hosting Support Forums
July 30, 2010, 06:39:30 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Host your website for $10 a year, visit Geekempire Hosting
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Simple PHP Hit Counter using a text file  (Read 567 times)
mpananen
Administrator
Newbie
*****
Posts: 44


« on: April 17, 2008, 01:11:49 PM »

Create an empty text file called counterlog.txt and upload it to the same directory as the page you want to count hits for.
Change the permissions of the counterlog.txt file to 777.

Insert the following code into your web page:

Code:
<?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>" $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);

?>

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!