Ok so I’ve got the entire registration system working, and the forgotten password. but for some reason I can’t set the cookies. When I look at the source after getting “Warning: Cannot modify header information – headers already sent” I notice that “</head><body>” is showing up twice for an unknown reason. I’ll just post the important code (skipping all the different action possible).
[code=php]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<?
function login($user,$pass) {
$loginsql = “SELECT * FROM users WHERE email='”.$user.”‘”;
$loginresult = mysql_query($loginsql);
if ( mysql_num_rows($loginresult) == 0 ) {
return FALSE;
} else {
while ( $row = mysql_fetch_array( $loginresult ) ) {
if ( $user == $row[’email’] ) {
if ( $pass == $row[‘password’] ) {
$cookielength = 60*60*24*10;
setcookie(“Username”, $row[’email’], $cookielength);
setcookie(“login”, TRUE, $cookielength);
setcookie(“userid”, $row[‘idusers’], $cookielength);
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
}
}
if ( isset ( $_GET[action] ) ) {
$action = $_GET[action];
} else {
$action = ‘form’;
}
if ( $action == ‘submit’ ) {
if ( login( $_POST[’email’], $_POST[‘pass’] ) ) {
$content = “<h2>Thanks for logging in.</h2>”;
} else {
$content = “<h2>Login Failed!</h2>”;
}
} elseif ( $action == ‘form’ ) {
….
}
?>
</head><body>
<?
echo $content;
?>
</body>
</html>
By two closed head open body statements in the source i mean the error page is:
[quote]
Warning: Cannot modify header information – headers already sent by (output started at /home/rdenni5/public_html/family/login.php:6) in /home/rdenni5/public_html/family/login.php on line 28
Warning: Cannot modify header information – headers already sent by (output started at /home/rdenni5/public_html/family/login.php:6) in /home/rdenni5/public_html/family/login.php on line 29
Warning: Cannot modify header information – headers already sent by (output started at /home/rdenni5/public_html/family/login.php:6) in /home/rdenni5/public_html/family/login.php on line 30
Thanks for logging in.
and the source of that is:
[code=php]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
</head><body><h2>Login Failed!</h2>
</body>
</html>
Hope that is enough information for you. Sorry if its too much.