help with counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

help with counter

Post 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?
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post 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]
Post Reply