Why i get everytime the error-message that i've already sent the headers

Posted by mikep on Stack Overflow See other posts from Stack Overflow or by mikep
Published on 2010-05-10T16:57:27Z Indexed on 2010/05/10 17:04 UTC
Read the original article Hit count: 244

Filed under:
|
|
|
|

Hey,

i've another question about web-programming.

I programmed a login script, but everytime when i try to login it says that i've send the header informations already.

Here are the 2 files:

<?php
if($_GET['logout'] == 1) {
    setcookie('authorized', 1, time()-3600);    
}
?>

<!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 - photoAdminSite</title>
</head>

<style type="text/css"> 
    body {
    text-align: center;
    font-family: helvetica;
    }

    #loginForm {
    padding: 1em;
    background: #e3e3e3;
    width: 260px;
    margin: 3em auto 0;
    text-align: left;

    }
</style>

<body>

<div id="loginForm">
<form method="post" action="confirm_login_credentials.php">

<h2>LOGIN</h2>
<p>Username: <input type="text" name="username" /></p>
<p>Password: <input type="password" name="password" /></p>
<p><input type="submit" value="Login" name="submit" /></p>

</form>
</div>
</body>
</html>





<?php
$username = $_POST['username'];
$password = $_POST['password'];

require 'database.php';

$q = "SELECT id FROM users_photoadminsite WHERE user_name = '$username' AND password = '$password'";

$result = $mysqli->query($q) or die(mysqli_error());

if (mysqli_num_rows($result) == 1) {
    setcookie('authorized', 1, 0);
    header("Location: index.php");
} else {
    header("Location: login.php");  
}
?>

i would be really happy about some helpful answers.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql