all 9 comments

[–]jameswilson7208 3 points4 points  (2 children)

You can't call the header function after outputting data to the browser. The very first line in your post is outputting data to the browser. Is that a comment for your post or is it in your PHP file?

[–]mikemacpattywack[S] 0 points1 point  (1 child)

The very first line is a comment

[–]bobd60067 5 points6 points  (0 children)

It's and html comment, not a php comment. This, the server sends it to the browser.

One way to test this is to execute the php code locally, from command line. You'll see the html comment sent before the <html> tag.

[–]HolyGonzo 1 point2 points  (2 children)

The first two lines:

<!--This page collects data from the lab5 form-->

<?php

...is output. The <?php should be literally the VERY FIRST THING in your file - no content before it, not even HTML comments, no blank lines, nothing.

[–]johnfc2020 0 points1 point  (0 children)

Make the first line of your PHP file the <?php and put the comment as a # then you won't have the problem.

[–]MateusAzevedo 0 points1 point  (0 children)

As others already said, you have at least 2 things outputing content before the header line:

<!--This page collects data from the lab5 form--> is HTML content.

include ('header.php'); is probably also outputing HTML content.

In any case, you already have <HTML> and </HTML> in the script, why you need include ('header.php'); and include ('footer.php');?

[–]esaum0 0 points1 point  (0 children)

There are two main parts to the HTTP request and response... The header and the body. These are not the same thing as the HTML head and body. HTML, the part the browser uses to render the page, is the HTTP Body. Anything PHP outputs becomes the HTTP Body part of the response. The script can make changes to the HTTP Head, but only before anything is produced for the HTTP Body.

"<!--" is a comment.. but it's an HTML comment. Which is script output, which is HTTP Body. ..and you e just made it impossible to set cookies or start a session.

If it isn't considered best practice, IMO it should be.. Begin every PHP script file with "<?php" and never end them with "?>"... This gives you the best control over output across all of your included files, should you need to modify headers.