Hi guys, I'm trying to put a really simple text-based PHP hit counter in the footer of my page...but I'm getting two PHP errors when I use what I'm trying to do:
Here is the section of code in my footer that has all the basic footer info:
<div id="footer">
<div class="left">©2001-2009 <a href="http://paulritter.net">paulritter.net</a> Valid <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> & <a href="http://validator.w3.org/check?uri=referer">XHTML</a></div>
<div class="right">Design and coding by <a href="http://paulritter.net/about">Paul Ritter</a> <a href="<?=$this->url('/login')?>"><?=t('< Login >')?></a></div>
[COLOR="Red"]<br /><div class="right">Total Hits:
<?
$filename = "hit_counter.txt";
@$fptr = fopen($filename, "r+");
if ($fptr == NULL) {
@$fptr = fopen($filename, "w+");
fwrite($fptr, "1");
fclose($fptr);
echo "1";
}
else {
$data = fread($fptr, filesize($filename));
$dataInt = (int) $data;
$dataInt++;
rewind($fptr);
fwrite($fptr, $dataInt);
fclose($fptr);
echo $dataInt;
}
?></div>[/COLOR]
<div class="clearer"><span></span></div>
</div>
</div>
And I have a file called "hit_counter.txt" in the SAME directory as this PHP file. I have chmodded it to 777, so it should be writable.
Here are the errors I'm getting:
Warning: fwrite(): supplied argument is not a valid stream resource in /home/a9712442/public_html/themes/halloween/default.php on line 35
Warning: fclose(): supplied argument is not a valid stream resource in /home/a9712442/public_html/themes/halloween/default.php on line 36
Line 35 & 36 are these lines:
fwrite($fptr, "1");
fclose($fptr);
I looked up the error, and I thought it would be a permissions issue...but after chmodding the hit_counter.txt file to 777, I can't think why this error still occurs. Any help would be greatly appreciated! 😃