Forum Moderators: coopster
What would cause this?
If you have to output something before using header(), look into the output buffering functions in the php manual.
I do have an if/else and an includes though. I wouldn't have thought those would cause any problems though. Maybe I have done something else fundamentally wrong. This is how I have tried to do it:
if (!$var_from_previous_page) {
header("Location: http.../default.html");
break;}
else{
include ("../functions.php");
$conn=dbconnect();
$rurl_sql="select F5 from db_table
where F4 = '$var_from_previous_page'";
$rurl_result = mysql_query($rurl_sql, $conn);
$rurl = mysql_fetch_array($rurl_result);
header("Location: $detail[F5]");
break;}
header("Location: $rurl[F5]");
/* Make sure that code below does not get executed when we redirect. */
exit;
The error I'm still getting though is this:
Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/xx/functions.php:2) in /hsphere/local/home/xx/mydomain.com/redirect.php on line 12
Line 12 is: header("Location: $rurl[F5]");
I don't understand where that is coming from.
ob_start();
and then on the line just before your call to header() type this :
$output = ob_get_clean();
and as coopster said, add an exit after the header.
If the redirect works after that, then something in between ob_start() and ob_get_clean() is outputting to the screen and by moving ob_start() down through the code block, you should be able to nail it down.
I promise I will start reading my errors more carefully for now on!
ahmed - I will remember the ob_start(); thing, for the next time I have problems.
Thanks again!