Forum Moderators: coopster
I've got a counter script which I wrote, but it doesn't seem to be changing at all, just staying at 1. The code is split onto two pages as I have a page loading in a iframe in a page. The background page has the code for incrementing the counter, and the iframe page has the code for displaying the counter. It's displaying the count correctly, its just the wrong count! The code is as follows:
CODE FOR INCREMENTING COUNTER:
$counterfile = fopen("counter.txt","r"); // opens the counter file for wtiting to$counternumber = fread($counterfile,6);
$counternumber = $counternumber + 1;
fwrite ($counterfile, $counternumber);
fclose ($counterfile);
CODE FOR DISPLAYING COUNTER:
$fn = "counter.txt";
$fh = fopen ($fn , "r");
$count = fread ($fh, filesize($fn));
fclose ($fh);
print ("<b><div style=\"position: absolute; left: 525px; top: 10px; z-index: 6; font size: 24pt; font-family: Verdana, Arial, sans-serif; color: #000080\">$count</div>\n");
print ( "<div style=\"position: absolute; left: 527px; top: 12px; z-index: 5; font size: 24pt; font-family: Verdana, Arial, sans-serif; color: #CCCCCC\">$count</div></b>");// The two <div> tags should give the text a shadow effect
fopen [php.net]("counter.txt","r")
you are opeming for read only. use w+ or r+. I would imagine yor fwrite is failing.
fwrite() [php.net] returns the number of bytes written, or FALSE on error.
try
$success = fwrite ($counterfile, $counternumber);
if ($success == false) {
echo "oops";
}
bet it will say oops ;)