Make Urtutorials.com your homepage | Add to Favorites      


Simple Counter  

Page counter.
This tutorial will show you how to count the hits you get! Using a text file

Code:
Before starting you will need to create a new txt file. Leave the file blank and save it as counterlog.txt.

<?

// Where to save the log file. (your text file)
$fp = fopen("counterlog.txt", "r");

$count = fread($fp, 1024); 

fclose($fp); 

//this adds 1 to the page views
$count = $count + 1;

//"Views : 1" This is what will be displayed on your site.
echo "<p>Views : " . $count . "</p>";
$fp = fopen("counterlog.txt", "w"); 

fwrite($fp, $count);
 
fclose($fp); 
?>
Save this file as counter.php. You can either include it on a page or just put the code on the page and your done! *You need to CHMOD 777 counterlog.txt*
 
Discuss this tutorial in the Forum.

Other good stuff:-


Submited by:- Farooq Azam

Discussions Forum Login:-

Username:
Password:  

Remember Me    
Not a member?
Register here

Copyright © UrTutorials.com - All rights ® reserved A Publispain Group Website