I'm having some problems working with a new authentication script that I'm coming up with. Everything works except when I try to test throwing the script off. For instance, if someone enters a bad password. Here is the error that I get (and I know that the headers are already sent earlier in the script, but it should exit the script after they are sent on the first try and I should not get this warning.):
Warning: Cannot add header information - headers already sent by (output started at /home/sidewin/public_html/php/reg_test/do_authuser.php:12) in /home/sidewin/public_html/php/reg_test/do_authuser.php on line 37
Here is the code:
<?
if ((!$username) || (!$password)) {
header ( "Location: http://www.sidewinderlan.com/php/reg_test/show_login.html");
exit;
}
$db_name = "xxxxxxxxxxxx";
$table_name = "xxxxxx";
$connection = @mysql_connect ("localhost", "xxxxxxx", "xxxxxxxxx") or
die ("Couldn't Connect!");
$db = @mysql_select_db ($db_name, $connection) or
die ("Couldn't Select Database!");
$sql = "SELECT * FROM $table_name
WHERE username = \"$username\" AND password = password(\"$password\")
";
$result = @mysql_query($sql, $connection) or
die("Couldn't execute query!");
$num = mysql_numrows($result);
if ($num != 0) {
$msg = "<p>Congratulations, you're authorized!</p>";
} else {
header("Location: http://www.sidewinderlan.com/php/reg_test/show_login.html");
exit;
}
?>
<? echo "$msg"; ?>