Skip to content

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

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:

[php]header(location:"index.php");[/php]

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

[php]
ob_start();

//script

header("Location:file.php");

ob_end_flush();
[/php]

OR

[php]
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;
}
[/php]

OR

[php]
printf("<script>location.href=’errorpage.html'</script>");

[/php]

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

Published inphp

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *