authorisation problem



Hello I have a problem with authorisation. I'd like script to write
incorect login to the text file (by add_bad_login function) and when
it's everything all right to keep on doing sth, and the script doesn't
write incorect logins to file. Here is the code:

<?php
require_once("functions.php");

if ($_SERVER['PHP_AUTH_USER']!="")
add_bad_login($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'],
$_SERVER['REMOTE_ADDR' ],date("Y-M-d H:i:s"));
if(!isset($_SERVER['PHP_AUTH_USER']) or ($user=check_auth($_SERVER
['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']))==-1)
{
header("WWW-Authenticate: Basic realm=strefa chroniona");
header("HTTP/1.0 401 Unauthorized");
die("Podales zle haslo i/lub login<br/>");
}
?>


In the file functions.php there are some functions. Above I used only
two of them, and they codes are listed below:

function check_auth($login,$password) {
global $authArray;
for ($i=0;$i<count($authArray);$i++)
if ($login==$authArray[$i]["login"] and $password==$authArray
[$i]["password"])
return $i;
return -1;
}

function add_bad_login($login,$passwd,$ip,$time) {
$f=fopen(dirname(__FILE__)."/tmp/bad_logins.txt","a");
flock($f,LOCK_EX);
fwrite($f,$login."\t".$passwd."\t".$ip."\t".$time."\n");
flock($f,LOCK_UN);
fclose();
}

authArray is an array with logins, passwds and folders names:

$authArray=array(
array
("login"=>"AB","password"=>"qwerty","folders"=>"A_B"),
array
("login"=>"CD","password"=>"qwerty2008","folders"=>"C_D")
);

Everything works corectly but if I give incorect logins and look into
the text file I see nothing, this file is empty.
.