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:
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.Code:<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> <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> <div class="clearer"><span></span></div> </div> </div>
Here are the errors I'm getting:
Line 35 & 36 are these lines: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
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!Code:fwrite($fptr, "1"); fclose($fptr);![]()



Reply With Quote

Bookmarks