I've had stable php code in my site in a file findRecords.php as follows:
// inside findRecords.php....
<HTML>
<head>
<?php
include 'titleBar.php';
include 'topNavigationBar.php';
?>
</head>
require 'varsAndStatics.php'; // variables and statics used throughout
// other html in findRecords.php not shown here for brevity.....
Inside my topNavigationBar.php I output the html for my top-of-every-page navigation bar, along the lines of:
<div class="pageTopRowContainerLabel">
<a class="pageTopRowTextStyle"
href="http://localhost/myProj/index.php">HOME</a>
</div>
// more nav bar divs not shown....
Inside findRecords.php I do a simple database lookup and get some records and intend to display those records in the browser by using header() to switch over to a different page that displays those records (showRecords.php).
If you notice above, you can see above that in findRecords.php, an html header has already been sent with some html divs used to display my navigation bar, by way of the include 'topNavigationBar.php' statement.
Then I have a call to header() inside this same findRecords.php file to implement Post/Redirect/Get:
header("Location: http://localhost/myProj/showRecords.php", true, 303);
The above works fine. Upon finding records in the database I header() over to showRecords.php to display them.
Okay now I just added a heredoc to the varsAndStatics.php that has been included all along above in findRecords.php (see above). I now add the following heredoc to the long-time-stable file varsAndStatics.php:
echo <<<_RIDOFWHITESPACE
<br />
<script type="text/javascript">
function ridOfWhiteSpace(theFormElementFieldValue, bLtrsOnly, bLtrsNumsOnly)
{
// Remove whitespace
if(theFormElementFieldValue.indexOf(" ")!=-1)
{
var doozh = theFormElementFieldValue.split(" ").join("");
theFormElementFieldValue = doozh;
}
return theFormElementFieldValue;
}
</script>
_RIDOFWHITESPACE;
Now my call to header() above in findRecords.php breaks with a Header already sent error.
I do not know why the heredoc broke this stable code. AFTER ALL -- that call to header() and the nav bar code have been there for a while!
What I'm saying is this: the page sent by findRecords.php sends the nav bar divs due to the include topNavigationBar.php -- and then I call header() -- that code has worked fine for quite a while.
In my opinion, because there has been output sent to the browser (the topNavigationBar.php divs) when I call header() in the old stable code, the adding of a heredoc() in varsAndStatics.php should not break the code.
Is there a subtlety I"m missing here?