Problemmer med Header i PHP login
Jeg har et problem med et php login, som jeg fandt på nettet. Men når jeg prøver at logge ind kommer dette frem:Warning: Cannot modify header information - headers already sent by (output started at /customers/darkrune.dk/darkrune.dk/httpd.www/downloads/sikker/index.php:7) in /customers/darkrune.dk/darkrune.dk/httpd.www/downloads/sikker/index.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /customers/darkrune.dk/darkrune.dk/httpd.www/downloads/sikker/index.php:7) in /customers/darkrune.dk/darkrune.dk/httpd.www/downloads/sikker/index.php on line 33
Koden ser sådan her ud:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Darkrune Sikker downloads</title>
</head>
<body>
<?php
$username = "user";
$password = "pass";
$randomword = "bibblebobblechocolatemousse";
if (isset($_COOKIE['MyLoginPage'])) {
if ($_COOKIE['MyLoginPage'] == md5($password.$randomword)) {
?>
CONTENT HERE
<?php
exit;
} else {
echo "<p>Bad cookie. Clear please clear them out and try to login again.</p>";
exit;
}
}
if (isset($_GET['p']) && $_GET['p'] == "login") {
if ($_POST['name'] != $username) {
echo "<p>Sorry, that username does not match. Use your browser back button to go back and try again.</p>";
exit;
} else if ($_POST['pass'] != $password) {
echo "<p>Sorry, that password does not match. Use your browser back button to go back and try again.</p>";
exit;
} else if ($_POST['name'] == $username && $_POST['pass'] == $password) {
setcookie('MyLoginPage', md5($_POST['pass'].$randomword));
header("Location: $_SERVER[PHP_SELF]");
} else {
echo "<p>Sorry, you could not be logged in at this time. Refresh the page and try again.</p>";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?p=login" method="post"><fieldset>
<label><input type="text" name="name" id="name" /> Name</label><br />
<label><input type="password" name="pass" id="pass" /> Password</label><br />
<input type="submit" id="submit" value="Login" />
</fieldset></form>
</body>
</html>