January 18th, 2003, 01:49 AM
|
#1 (permalink)
|
| Ultimate Member
Join Date: Oct 2001 Location: Trent University
Posts: 2,414
| Can't modify header info??
I've been trying to setup a simple login page using php and a mysql database on a windows server using php 4.3.0.
Once if got all the code written, it keeps telling me that I can't modify the header info. This is the error that is produced. Quote:
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\login.php:8) in c:\inetpub\wwwroot\login.php on line 10
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\login.php:8) in c:\inetpub\wwwroot\login.php on line 11
Sorry - you need valid credentials to access this resource.
| The following is the code that I'm using. PHP Code: <?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"The Willycorp Network\"");
header("HTTP/1.0 401 Unauthorized");
// only reached if authentication fails
echo "Sorry - you need valid credentials to access this resource.\n";
exit;
} else {
mysql_connect("localhost","*******","*******");
mysql_select_db("test");
$result = mysql_query("SELECT ID FROM userauth WHERE Username = '{$_SERVER['PHP_AUTH_USER']}' AND Password = '{$_SERVER['PHP_AUTH_PW']}';");
if (mysql_num_rows($result)) {
// only reached if authentication is successful
echo "Welcome to the Willycorp Network.";
} else {
header("WWW-Authenticate: Basic realm=\"The Willycorp Network\"");
header("HTTP/1.0 401 Unauthorized");
echo "Sorry - you need valid credentials to access this resource.\n";
}
}
?> Anyone have any idea what the hell is going on with this code? |
| |