Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do I ge ant error for header() function?

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
I am useing this code:
...

} else {

header("Location: /auth.php");
exit();

}

}

?>

And i get this error:

"Warning: Cannot modify header information - headers already sent by (output started at (path of file...)"

I have no ideas why. Could someone shed some light on this for me?
 
You get hat message because you have already output something to the page. Headers have to be sent before any other form of output... even whitespace. And that could very well be the problem... you may be delivering some whitespace (check before/after your <? and ?> tags) by accident.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Thats so strange, I have white spaces everywhere how would I know which ones (if any are causing the problem?

<html>
<table border=1>
<form name="login" action="login.php" method="post">
<tr>
<td>
UserName;
<input type="text" value="" name="uname">
</td><td rowspan="2"><p>Please enter your username and password to gain access to the Dev Arch Request Page<br></p></p>New user? Click <a href="newuser.htm">here</a></td></tr>
<tr><td>
Password;
<input type="password" value="" name="pword">
<br>
<input type="submit">
</td></tr>
</form>
</table>
</html>
<?php

$uname = $_POST['uname'];
$pword = $_POST['pword'];
$stateVar = "Open";
$currtime = date("H:i");
$currdate = date("j/m/y");

if(($uname=="") || ($pword=="")) {

echo "Missing field please try again";


}else{

mysql_connect("localhost", "root", "monkey") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$result = mysql_query("SELECT * FROM devArch_emp WHERE username='$uname'") or die(mysql_error());

while($rowsAll = mysql_fetch_array( $result ))
{
$name = $rowsAll['name'];
$email = $rowsAll['email'];
$deskno = $rowsAll['deskno'];
$extno = $rowsAll['extno'];
$password = $rowsAll['password'];
}

if(!($pword == $password)){

echo "Incorrect Username or Password, Please try again";

} else {

header("Location: /auth.php");
exit;

}

}?>
 
BabyJeffy said:
Headers have to be sent before any other form of output
So wrt the example you gave above... the <? would have to be the very very very first thing in the php file... and you would not echo or output anything to the page (including HTML and a doctype etc) until you had sent the headers.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Thats is such an awkward function. My first php grudge!!

Thanks alot for your help Jeff it is greatly appreciated :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top