Jump to content

Problem fixing "Warning: Cannot modify header information"


A JM

Recommended Posts

I'm having a problem solving the following problem that I am having with the Submittal of a form. After the Submit button I am inserting records into a database and then wanting to redirect to a confirmation page but I'm getting the following error and am not sure how to resolve the problem.

 

Any suggestions of ideas I can follow?

 

Thanks.

 

AJM,

Warning: Cannot modify header information - headers already sent by (output started at /home/content/91/4761691/html/pages/claim.php:82) in /home/content/91/4761691/html/pages/claim.php on line 226
$insertGoTo = "confirm.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));

 

Is that output to the user or submitted to the DB?

 

Just not 100% on what "output" is referring to..

 

Thanks,

 

Output as in echo'ing or print'ing to the stdout, as in sending to the user.

 

Any writing to files, database, network etc is sparate.

Try ob_start(); and ob_flush(); It should be able to solve your problem. Just place ob_start at the very top after your <?php and ob_flush at the very end of your document.

 

You can, but in reality you should know that you're redirecting before outputting anything (e.g. like in a MVC framework)

The offending code does not have any echo or print functions within it but there is some echo'ing going on in some of the JavaScript..

 

I've removed the offending echo() from the javascript section and tried the page again but still get the same error, I'm confused on how to track this down.

 

The form is posting correctly as the data is written as designed I just can't get it past the header() redirect.

 

Is there an alternative on how to track down where the offending code is?

I found the answer to my issues in that have multiple php tags that need to be combined and they had a blank line in between them, ugh!!!!

 

3) Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.

 

 

http://www.tech-recipes.com/rx/1489/solve-php-error-cannot-modify-header-information-headers-already-sent/

 

Many thanks for the suggestions and assistance.

 

AJM,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.