A JM Posted April 19, 2015 Share Posted April 19, 2015 (edited) 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)); Edited April 19, 2015 by A JM Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/ Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 19, 2015 Share Posted April 19, 2015 To use header() there must be no output before it! It looks like there is some output before header() is called, on line 82 of claim.php Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509369 Share on other sites More sharing options...
A JM Posted April 19, 2015 Author Share Posted April 19, 2015 Is that output to the user or submitted to the DB? Just not 100% on what "output" is referring to.. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509372 Share on other sites More sharing options...
PHPEnthusiast Posted April 19, 2015 Share Posted April 19, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509374 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 19, 2015 Share Posted April 19, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509375 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 19, 2015 Share Posted April 19, 2015 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) Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509377 Share on other sites More sharing options...
A JM Posted April 19, 2015 Author Share Posted April 19, 2015 (edited) 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? Edited April 19, 2015 by A JM Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509395 Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 19, 2015 Share Posted April 19, 2015 The JS is irrelevant server side it only operates client side. The output may come from an error!?! What is on line 82 of claim.php? Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509396 Share on other sites More sharing options...
A JM Posted April 19, 2015 Author Share Posted April 19, 2015 Nothing more than the php tags.. see attached. Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509398 Share on other sites More sharing options...
Solution A JM Posted April 19, 2015 Author Solution Share Posted April 19, 2015 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, 1 Quote Link to comment https://forums.phpfreaks.com/topic/295687-problem-fixing-warning-cannot-modify-header-information/#findComment-1509399 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.