When you use a PHP function that manipulates the headers such as http:
- header ()
- setcookie ()
- session_start ()
It is important to use these functions before they generated any flows to the client. From the moment information was sent to the client (usually a top display a web page), it means that the HTTP headers have already been automatically sent to the client. This type of feed is frequently sent with the functions echo, print, etc..
If there is a free before the opening of the first php tag, then this space could be sent as the top web client and therefore http headers in the preceding automatically mean the client what type of feed it question. Here is an example of a head with the homepage CCM:
Keep-Alive: timeout = 15, max = 50
Content-type: text / html; charset = iso-8859-1
So it is important to understand the system:
- I echo or print at the beginning of my script. Ditto, if I have a space in my script that is not included in my php tags, it will be considered as part of the source of the page to send and headers precede. This may cause an error of the kind which seeks the solution for several days :-)
- The server sends this data, and preceded by failure of headers which means that this is an html page.
- If after this in my script I use a function key to the headers, it can no longer do so because the headers have already been sent. I get an error like "headers already sent".