Welcome to WebmasterWorld Guest from 184.108.40.206 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Subscribe and Support WebmasterWorld
PHP and Counters circuitjump msg:1301184 2:44 pm on Jul 30, 2001 (gmt 0) How do I make a counter in PHP?
I've tried it this way;
$counter = 0; $counter = ++$counter; print $counter." line<br>";
And it does not work.
Anyone got any ideas?
David msg:1301185 3:11 pm on Jul 30, 2001 (gmt 0)
That looks like it should increment. As long as you don't reset $counter to 0 on each call.
How are you saving the variable $counter?
circuitjump msg:1301186 3:21 pm on Jul 30, 2001 (gmt 0)
actually, that was my problem.
I was reseting it back to zero. Since I had it in a loop I was'nt paying attention to how it was working.
Thanks for the help
toadhall msg:1301187 8:24 pm on Jul 30, 2001 (gmt 0)
Give this php a whirl: /* just make up a file called counter.txt with one line - "0" (no double quotes) */ <? $counter = file("counter.txt"); echo ("You are visitor number $counter!\n"); $newcount = ++$counter; // update counter.txt $file = fopen("counter.txt","w"); fwrite($file,"$newcount"); fclose($file); ?>