Ok, it is me again. Having a really frustrating problem with user authentication. When I run my script below I get the following error messages: (I have marked the area in question with a comment in caps)
Warning: Cannot add header information - headers already sent by (output started at c:\program files\easyphp\www\computerzonehq\admin\login.php:1) in c:\program files\easyphp\www\computerzonehq\admin\login.php on line 44
Warning: Cannot add header information - headers already sent by (output started at c:\program files\easyphp\www\computerzonehq\admin\login.php:1) in c:\program files\easyphp\www\computerzonehq\admin\login.php on line 45
Here is the code
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Connect to MySQL
mysql_connect( 'localhost', 'root', '' )
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db( 'computerzonehq' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
//HERE IS WHERE IT IS HAVING THE PROBS
header( 'HTTP/1.0 401 Unauthorized' );
header( 'WWW-Authenticate: Basic realm="Computerzone HQ Admin"' );
echo 'You are not authorized to view this page!<BR>
';
exit;
}
else {
//display authorized information
echo '
<P>You are logged in as '.$PHP_AUTH_USER.'!</P>
';
}
?>
I think I know what it is saying. It is saying that the info has already been sent right? But it has not. I have tried restarting pc and apache and I get the same message.
Thanks😕