עזרה ממש קלה ב-PHP
יש לי קובץ COUNTER פשוט לגמרי, שמעלה את המונה באחד בכל כניסה לדף. אני מבקשת קובץ דומה שמאפס את המונה. קלי קלות אבל אני לא יודעת לעשות את זה...תודה.
יש לי קובץ COUNTER פשוט לגמרי, שמעלה את המונה באחד בכל כניסה לדף. אני מבקשת קובץ דומה שמאפס את המונה. קלי קלות אבל אני לא יודעת לעשות את זה...תודה.
<? function counthit() { global $hitcount; $pagename = $_SERVER['PHP_SELF']; $countertxt = 'counter.txt'; $err = '<font color="red">Could not write to file. Make sure you you have write permission</font>'; // if file doesn't exist, attempt to create it if (!file_exists($countertxt)) { $fp = @fopen($countertxt,"w"); if (!$fp) die($err); fclose($fp); } $fp = @fopen($countertxt,"r+"); // read in the page values and look out for current page $cnt = 0;$hitcount = 0;$found = false; while ($line = fgets($fp)) { $data = explode(':',$line); if ($data[0] == $pagename) { $found = true; $hitcount = (int)$data[1]+1; $cnt += strlen($data[0])+1; break; } $cnt += strlen($line); } // page was not found, so add it if (!$found) { if (is_writable($countertxt)) { fwrite($fp,((filesize($countertxt) == 0)?'':"\r\n").$pagename.':0000000000000001'); $hitcount = 1; } else die($err); } // page was found, so update its count else { if (is_writable($countertxt)) { fseek($fp,$cnt); fwrite($fp,str_pad($hitcount, 16, '0', STR_PAD_LEFT)); } else die($err); } } ?>