I can't figure out what I'm doing wrong with this script. It will only go through the file and use the first user information It wont go to the next line. You can see this script in action at Http://www.gerbilscentral.com/index.shtml go to the bottom of the page and use the login test, test.
<?PHP
if(!isset($PHP_AUTH_USER)){
header('WWW-Authenticate: Basic realm="Gerbils Central Society"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required';
exit;
} else if(isset($PHP_AUTH_USER)) {
$filename="/u155/awebking/cgi-bin/society/users.txt";
$fp=fopen($filename, "r");
$file_contents=fread($fp, filesize($filename));
fclose($fp);
$line=explode("\r", $file_contents);
}
for($i=0;$i<=sizeof($line);$i++){
$data_pair=explode(":", $line[$i]);
if(($data_pair[1] == $PHP_AUTH_USER)&&($data_pair[2] == $PHP_AUTH_PW)){
$auth=1;
break;
} else {
$auth=0;
}
}
if($auth=="1"){
echo "<h3>Welcome <a href=mailto:$data_pair[3]>$data_pair[0]</a> to the Gerbils Central Society</h3>";
} else {
header('WWW-Authenticate: Basic realm="Gerbils Central Society"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required';
exit;
}
?>
you can login successfully with the username: awebking and password: a071584a
This is the first line of information stored in the file users.txt