Page 1 of 1

help with counter

Posted: Sun Sep 10, 2006 1:55 pm
by danharibo
I am making a counter, but it wont Count :(

Code: Select all

Page Viewed <?
$fp = fopen('Siteviews.txt', 'r+'); // Open Page .txt for reading from beginning
$read = fread($fp, '1000'); // Read from the file pointer
print($read); 
$read+1;
$read = fread($fp, $read); ?>
 Times<br>
any ideas?

Posted: Sun Sep 10, 2006 2:01 pm
by speedy33417
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is what I found a while ago and it works for me. You need to beef it up for your taste.

Good luck.

Code: Select all

<?php 
$file = fopen("counter.txt",(is_file("counter.txt"))?"r+":"w+"); 
$count = fread($file, filesize("counter.txt")); 
rewind($file); 
$count +=1; 
fputs($file, $count); 
fclose($file); 
echo "You are visitor : $count"; 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]