I made a login program for my site, you type in a username and password, if they are correct, it is suppost to register it to a cookie. I have this login code, this is what is exacuted when the username and password are entered on another script:
<?
Require_Once("functions.php");
$loginvar = login($username, $password);
if(!loginvar) {
}
else {
echo "\$username = $username";
setcookie("siteuser", "$username");
$validuser = $HTTP_COOKIE_VARS['siteuser'];
}
MakeHeader(Login);
if (!$loginvar) {
}
else {
echo "\$validuser = $validuser";
echo "You have been logged in<br>";
}
echo "<meta http-equiv=\"refresh\" content=\"3 URL=index.php\">";
echo 'You will be taken back to the page you came from';
MakeFooter();
?>
This is the login function
function login($username, $password) {
sleep(1);
$connection = dbconnect();
if (!$connection) {
echo "<B>ERROR:</B> Could not connect to the database...<br>";
return false;
}
$password = md5($password);
$query = "select * from User
where username = '$username'
and password = '$password' ";
$result = mysql_query("$query");
if (!$result) {
echo "<b>ERROR:</b> Could not get query...<br>";
return false;
}
if (mysql_num_rows($result) > 0) {
return true;
}
else {
echo "<font color=red>That username doesn't exist or the password is incorrect<br>";
return false;
}
}
I get an error Warning: Cannot add header information - headers already sent by (output started at /home/mark/public_html/login.php:8) in /home/mark/public_html/login.php on line 9
and the cookie doesn't seem to be registered. What is wrong?