Hi!
I am trying to write a simple script, which checks and authorises users trying to access some pages on server. It mostly works, but one thing doesn't. I cannot figure out the mistake. The userid and password are passing from simple html form into the script as variables. Then the script check if the variables not empty and after that, it search in an array, which contains the contents of plain text file with pairs like:"(userid)🙁md5 encrypted password)". If userid:password pair exits in the file scripts works fine, but when I input wrong userid and wrong password I get next message in my browser window: Warning: Undefined offset: 3 in c:\devel\apache\htdocs\checkuser.php on line 18.
Below I put the source of the script. Any help will be appreciated a lot!
<?php
$filename="c:\devel\apache\parol.txt";
if (!($userid && $password))
{
echo "Please, return back and fill in your userid and password!";
exit;
};
$fp=fopen($filename, "r");
$contents = fread ($fp, filesize($filename));
$userstring=$userid.":".md5($password);
$filestring=explode("\n", $contents);
//print "$filestring";
$i=0;
while ($i <=sizeof($filestring))
{
if ($userstring == $filestring[$i])
{
$auth = 1;
break;
}
else
{$auth = 0;
}
$i++;
}
if ($auth)
{
echo "You are authorised!";
}
else echo "Authorization Required!";
?>