perhaps a little clarification on how webpages are served.
The headers come first in the server response. after they're done, there is a blank line, and then the content of the webpage follows (which the browser renders). For example:
Code:
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="generator" content="vBulletin 3.8.1" />
<meta name="keywords" content=" php cookies, dhtml, javascript, css, dynamic html, xml, html, php, cgi" />
<meta name="description" content="Page 2- php cookies PHP" />
<link rel="shortcut icon" href="favicon.ico" />
<!-- blah blah blah etc etc..........-->
in this example, the last header is the content-type header. the blank line below signals the end of the headers, and the following line (in this case, with the doctype) is the first line of content.
once php outputs anything that is not a header (e.g., text, error messages, html markup, even whitespace or html comments), then the headers end on no more headers can be sent. When you try to use a function that sets headers (like header() or setcookie()) after content has been output, you get the "...headers already sent" error, because you can't "back up" and serve another header after that section of the server response is complete.
Bookmarks