Lars Gullik Bjønnes wrote:

> Angus Leeming <[EMAIL PROTECTED]> writes:
> | Index: end.php3
> | -if ($counter_file) {
> | +if (isset($counter_file)) {
> |         counter($counter_file);
> |  }
> 
> Then you need an else clause, I belive that counter() emmits a
> warning messge if it is unable to open the file.
> 
> That message, or one similar should be output if the file is not set
> at all.

I think the point is that all pages include end.php3, but only 
index.php3 in www-user sets 
        $counter_file = "counter/counter.txt"; // file for the hit counter
So, I think that the current code is correct.

Having said that, my php is even less than my perl. It looks to me 
like the current 'counter' function should cope with an empty $c_file 
(see below), but I can make the change if you want. Do you think this 
necessary? Let me know and I'll commit the appropriate changes to 
end.php3 in both www-devel and www-users.

// Stolen from rofus ([EMAIL PROTECTED]), modified
function counter($c_file) {
-        if (file_exists($c_file)) {
+        if ($c_file && file_exists($c_file)) {
                $aprif = fopen($c_file,"r+");
                $checkme = flock($aprif, 2); //lock write only
                $hits = fgets($aprif, filesize($c_file));
                rewind($aprif);
                $hits += 1;
                $checkme = fputs($aprif,"$hits\n");
                $checkme = flock($aprif, 3); //unlock
                fclose($aprif);
                echo("<p>At least $hits hits on this page.</p>\n");
        } else {
                echo("<p>The webmaster needs to fix the 
counter</p>\n");
        }
}

-- 
Angus

Reply via email to