Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP and Counters

   
2:44 pm on Jul 30, 2001 (gmt 0)

10+ Year Member



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?

3:11 pm on Jul 30, 2001 (gmt 0)

10+ Year Member



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?

3:21 pm on Jul 30, 2001 (gmt 0)

10+ Year Member



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

8:24 pm on Jul 30, 2001 (gmt 0)

10+ Year Member



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[0]!\n");
$newcount = ++$counter[0];
// update counter.txt
$file = fopen("counter.txt","w");
fwrite($file,"$newcount");
fclose($file);
?>