Monday, 24 November 2014

Headers already sent by .....

  • When using PHP function that handles the HTTP headers such as:

header () 
setcookie () 
session_start () 
  • Consider, using these functions before they generated any information to the client. From the moment information was sent to the client, it means that the HTTP headers have already been automatically sent to the client. This type of feed is frequentwith the functions like echo, print, etc..


If there is a free space before the opening of the first php tag, then this space could be sent to the web client. 

Here is an example of a head with the Kioskea homepage : 


Server: Apache
X-Powered-By: Php/4.4.0-0.dotdeb.0
Keep-Alive: timeout=15, max=50
Connection: Keep-Alive
Transfert-Encoding: chunked
Content-type: text/html; charset=iso-8859-1
  • The aim is to understand how the system works:
  • When using echo or print at the beginning of a script and there 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.
  • The server sends this data preceded by headers as an html page.
  • If after this a function related to the headers is used in the script, it can no longer do so because the headers have already been sent. You should be prompted by the error message "headers already sent".

0 comments:

Post a Comment