tags:

views:

40

answers:

4

my code-

<?php

$username = $_POST['username'];
$password = $_POST['password'];

require 'database.php';

$q = "SELECT id FROM users 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");  
}

?>

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\pics\database.php:1) in C:\xampp\htdocs\pics\confirm_login_credentials.php on line 13

there is no white space and BOM is also ASCI

+2  A: 

output started at C:\xampp\htdocs\pics\database.php:1

That's where you should look for anything that gets echoed. (1 means line 1)

Mchl
You may want to remove the closing ?> tag from the bottom of database.php to ensure no whitespaces creep in after your code.
Cags
+2  A: 

Your database.php file is outputting something on line 1. Likely some whitespace character or BOM.

Daniel Egeberg
+1  A: 

amanda, even though this error is on line 1. the ending ?> tags in a PHP script are optional.

It's good practise to never put these in so that you don't get whitespace at the END of your while and then you can't use header() and get this classic "Headers already sent" error.

You can prevent against this by using the headers_sent() function which is more robust than just firing out header() calls.

if(headers_sent() === false) {
    header("Location: myfile.php");
} else {
    die('I cant redirect because headers have already been sent');
}

With regard to your problem, check whitespace before the <?php tag in all your relevant files, most likely database.php.

Paul Dragoonis
I don't really think so. You're still left in an error condition regardless. It's better to write your code so it won't happen in the first place.
Daniel Egeberg
Agreed it was a demonstration how to find if headers have already been sent or not, not a solution to the problem. The only resolution is to remove the whitespace or whatever is outputting headers.
Paul Dragoonis
A: 

check BOM of your database.php file. it should be ANCI

nectar