i am trying to setup a basic authentication procedure for a web page but cannot get it to work. (ie person logs in and the script compares the login details with those stored in a text file) Can someone please tell me what exactly these warning mesages mean:
Warning: Cannot add header information - headers already sent by (output started at /home/d/daverroc/.HTMLinfo/assign2/login.php:14) in
/home/d/daverroc/.HTMLinfo/assign2/login.php on line 29
Warning: Cannot add header information - headers already sent by (output started at /home/d/daverroc/.HTMLinfo/assign2/login.php:14) in
/home/d/daverroc/.HTMLinfo/assign2/login.php on line 30
You have cancelled the Authentication process.
and how i can get the code below to work
thankyou
<?
if(!isset($PHP_AUTH_USER)){
header("WWW-Authenticate: Basic realm=\"Footy Tips\"");
header("HTTP/1.0 401 Unauthorized");
echo "You have cancelled the Authentication process.";
exit;
}
else{
//read in the entire file. Each order becomes an element in the array
$webpass = file("./webpass.txt");
// count the number of records in the array
$number_of_records = count($webpass);
echo "<table border=1>\n";
echo "<tr><th bgcolor = \"#CCCCFF\">Login</td>
<th bgcolor = \"#CCCCFF\">Password</td>
<tr>";
for ($i=0; $i<$number_of_records; $i++){
//split up each line
$line = explode( ";", $webpass[$i] );
if (($PHP_AUTH_USER=="$line[0]")&&($PHP_AUTH_PW=="$line[1]")){
// output record
echo "<tr><td align=center>$line[0]</td>
<td align=center>$line[1]</td>
</tr>";
}
else{
header("WWW-Authenticate: Basic realm=\"pluto\"");
header("HTTP/1.0 401 Unauthorized");
echo "You have cancelled the Authentication process.";
exit;
}
}
echo "</table>";
}
?>