Een vriend van me heeft voor me een script gemaakt, maar er zit een foutje in met de headers die voor de login cookie zorgen.
De fouten zijn:
Warning: Cannot modify header information - headers already sent by (output started at /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php:9) in /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php on line 25
Warning: Cannot modify header information - headers already sent by (output started at /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php:9) in /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php on line 26
Successful Login.
De code staat hier onder:
<!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>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?PHP
include('functions.php'); // This includes the database functions i made for the database.
$username = $_POST['Username']; // Get the username sent from the form.
$password = $_POST['Password']; // Get the password sent from the form.
$md5_password = md5($password); // MD5 Hash the password, for extra security.
$page_rank = 1; // The rank of this page. Using 1 as admin, but you can change this as long as you change the
// database to reflect the change.
Connect(); // Connect to the database.
$sql = "SELECT rank FROM users WHERE username = '$username' AND password = '$md5_password' AND rank = '$page_rank' LIMIT 0,1";
$query = mysql_query($sql);
if(mysql_num_rows($query) == 1){
$row = mysql_fetch_row($query);
setcookie('AdmUsername', $username, time()+60*60*24*30, '/', '', 0);
setcookie('AdmRank', $row[0], time()+60*60*24*30, '/', '', 0);
echo('<strong>Successful Login.</strong><br />'.chr(10));
} else {
echo('<strong>Login Failed.</strong><br />'.chr(10));
}
Disconnect(); // Disconnect from the database.
?>
</body>
</html>
ik heb geprobeerd de html onder de php te zetten, en zelfs volledig weg te doen, maar dat lukt niet:/
deze error:
Warning: Cannot modify header information - headers already sent by (output started at /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/functions.php:36) in /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/functions.php:36) in /usr/home/fh2028/domains/tdkclan.com/public_html/sites/Clantemp1/calender/login.php on line 18
Successful Login.
en dit is nu de login.php
<?PHP
include('functions.php'); // This includes the database functions i made for the database.
$username = $_POST['Username']; // Get the username sent from the form.
$password = $_POST['Password']; // Get the password sent from the form.
$md5_password = md5($password); // MD5 Hash the password, for extra security.
$page_rank = 1; // The rank of this page. Using 1 as admin, but you can change this as long as you change the
// database to reflect the change.
Connect(); // Connect to the database.
$sql = "SELECT rank FROM users WHERE username = '$username' AND password = '$md5_password' AND rank = '$page_rank' LIMIT 0,1";
$query = mysql_query($sql);
if(mysql_num_rows($query) == 1){
$row = mysql_fetch_row($query);
setcookie('AdmUsername', $username, time()+60*60*24*30, '/', '', 0);
setcookie('AdmRank', $row[0], time()+60*60*24*30, '/', '', 0);
echo('<strong>Successful Login.</strong><br />'.chr(10));
} else {
echo('<strong>Login Failed.</strong><br />'.chr(10));
}
Disconnect(); // Disconnect from the database.
?>
<!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>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
</body>
</html>
Voordat je setcookie aanroept, mag er absoluut geen output naar de browser zijn in de vorm van echo of iets dergelijks. De foutmelding zegt dat er op regel 36 van functions.php wel iets ge-output wordt.
Een stoplap is ob_start () aan het begin van je script en ob_end_flush () aan het einde van je script, maar het is netter om eerst alle logica af te handelen voordat je iets terugstuurt naar de browser.