Forum Moderators: coopster

Message Too Old, No Replies

PHP Redirect using header()

Warning: Cannot modify header information - headers already sent by (

         

CTHouston

8:07 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



Using this code, when i provide incorrect username and password, it should redirect me to a separate login page. unfortunately, instead of redirecting me, it gives me the following error:
"Warning: Cannot modify header information - headers already sent by (..."

<?php

echo $_SERVER['HTTP_REFERER'];

if ($_POST['user'])
{

$link = mysql_connect('localhost','username','password') or die('Could not Log onto Server<br />');
$db_connect = mysql_select_db('database',$link) or die('Could not Connect to Database<br />');

$query = "select * from users where uid = '{$_POST[user]}';";
$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {
header("location: mods/login.php");
exit;
}
else {
$uid=mysql_result($result,0,0);
$pass=mysql_result($result,0,1);
$email=mysql_result($result,0,2);
$name=mysql_result($result,0,3);
$admin=mysql_result($result,0,4);
$url=mysql_result($result,0,5);
if ($pass==$_POST['pass'])
{
if ($admin==1)
{
require("mods/admin.php");
}
else
{
require("mods/client.php");
}
}
else {
header("location: mods/login.php");
exit;
}
}
mysql_close($link) or die('Could not Close Link to Server<br />');
}
else
{
header("location: index.htm");
exit;
}
?>

Can anybody tell me why it wont work?

Timotheos

8:50 pm on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome CTHouston!

You can't output anything before the header function, not even a space. Sooo the echo at the very top is killing you ;-)

CTHouston

9:01 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



Wow, im retarded, i know that i cant output anything before header, i just forgot about that echo. I was using it for trouble shooting. Thanks!

Timotheos

9:11 pm on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the dumhead club... I'm a charter member ;-)