total{debug} total{debug}
>_ post

Warning: Cannot modify header information – headers already sent by…

Heads up — this article is over 180 months old. Some of the details may have changed since it was written.

Ok so today i was doing some PHP coding and get the dreaded header error caused me a bit of a headache as i needed to redirect some pages. After a bit of searching i managed to find an alternative to using:

1
header(location:"index.php");

So to get rid of the error that this produces simply change it to any of the below:

1
2
3
4
5
6
7
ob_start();

//script

header("Location:file.php");

ob\_end\_flush();

OR

1
2
3
4
5
6
7
8
9
10
if ($success)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=success.php">';
exit;
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=retry.php">';
exit;
}

OR

1
printf("<script>location.href=&#8217;errorpage.html'</script>");

I used the last option as I found this worked best compared to the others with my program however they may all work well for your application