Counter script
From: russdh (russdh_at_hotmail.com)
Date: 09/30/04
- Next message: Bruno: "Strip line feeds and carriage returns"
- Previous message: Andrew _at_ Rockface: "Re: input validation - only vdaemon?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Sep 2004 13:52:29 +0000 (UTC)
Hi
I'm pretty new to PHP scripting and I've been messing around with a very
simple counter script. Everything works fine apart from the occasional reset
of the counter file. I realised that this could be caused by 2 or more users
accessing this file at the same time and thought about using the flock()
procedure somewhere in the script but I'm not too sure how it should be
implemented. The code is below.
<?
$log = 'counter/counter.txt';
$output_str = "";
// Open log file, read log file value, increment value, write to logfile,
close.
$open=@fopen($log,'r+');
$counter=@fread($open,filesize($log));
@fclose($open);
$counter++;
$write=fopen($log,'w');
fputs($write,$counter);
fclose($write);
// Format numbers on page along with leading zeros.
$leading = 7;
$len_str = strlen($counter);
$leading_zeros = ($leading - $len_str);
for($y=0;$y<$leading_zeros;$y++){
$output_str = $output_str . "<img src=\"counter/0.gif\" height=20
width=15 ALT=\"0\">";
}
for($i=0;$i<$len_str;$i++){
$digits = substr($counter,$i,1);
$output_str = $output_str . "<img src=\"counter/$digits.gif\" height=20
width=15 ALT=\"$digits\">";
}
echo ("<p align=center><font class=f7>You are visitor
number</font><br><table cellpadding=0 cellspacing=0 width=105 height=20
border=1><tr><td width=105 height=20>" . $output_str .
"</td></tr></table></p>");
?>
Any help would be greatly appreciated.
Many thanks.
Russ.
- Next message: Bruno: "Strip line feeds and carriage returns"
- Previous message: Andrew _at_ Rockface: "Re: input validation - only vdaemon?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|