homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP and Counters
circuitjump

10+ Year Member



 
Msg#: 266 posted 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

10+ Year Member



 
Msg#: 266 posted 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

10+ Year Member



 
Msg#: 266 posted 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

10+ Year Member



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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved