Naked Forum Index » PHP Snipper
Text file hit counter
Site Admin
Joined: 23 Oct 2004
Posts: 163
Joined: 23 Oct 2004
Posts: 163
If your counter.php n counterlog.txt is not in main dictionary of your website , then you must to change your counter.php and the included code a little bit .
Lets say that you make counter.php n counterlog.txt inside de map News :
- http://www.yourdomain.com/News/counter.php
- http://www.yourdomain.com/News/counterlog.txt
The code of your counter.php will be like this :
<?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 ( "/home/YourUserNameAtYourServer/public_html/News/counterlog.txt" , "r" );
// Get the existing count
$count = fread ( $fp , 1024 );
// 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 ( "/home/YourUserNameAtYourServer/public_html/News/counterlog.txt" , "w" );
// Write the new count to the file
fwrite ( $fp , $count );
// Close the file
fclose ( $fp );
?>
Your Included code will be like this :
<?php
include '/home/YourUserNameAtYourServer/public_html/News/counter.php';
?>
See the working script : Dinand Fansite
Lets say that you make counter.php n counterlog.txt inside de map News :
- http://www.yourdomain.com/News/counter.php
- http://www.yourdomain.com/News/counterlog.txt
The code of your counter.php will be like this :
Quote:
<?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 ( "/home/YourUserNameAtYourServer/public_html/News/counterlog.txt" , "r" );
// Get the existing count
$count = fread ( $fp , 1024 );
// 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 ( "/home/YourUserNameAtYourServer/public_html/News/counterlog.txt" , "w" );
// Write the new count to the file
fwrite ( $fp , $count );
// Close the file
fclose ( $fp );
?>
Your Included code will be like this :
Quote:
<?php
include '/home/YourUserNameAtYourServer/public_html/News/counter.php';
?>
See the working script : Dinand Fansite
All times are GMT + 1 Hour
Page 2 of 2
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Chairs table
free template v.1.2.3 © Jasidog.com.
Powered by phpBB © phpBB Group
Powered by phpBB © phpBB Group








