1

Possible Duplicate:
header() error not shown in php

My /etc/php5/apache2/php.ini file has the next configuration:

display_errors = On
log_errors = On
error_reporting = E_ALL | E_STRICT

and I can view errors like Undenifed variable, Parse error and so on in the browser, but with the next code

<!DOCTYPE html>
<?php
   header('hola: adios');
?>

I can't see the Headers already sent error. Also with the Developer tools of Chrome I can see that the header hola: adios is set. How could I see those type of errors? Thanks.

Community
  • 1
  • 1
Marcos
  • 4,643
  • 7
  • 33
  • 60
  • 2
    You have automatic output buffering on, hence, there is no error.... – Wrikken Dec 12 '12 at 01:14
  • @Wrikken I have set `output_buffering = Off` in my php.ini and restarted apache but no difference. – Marcos Dec 12 '12 at 01:26
  • Well, in that case, what does phpinfo() at that exact point say about output buffers, error reporting levels, display error settings, et al. ? – Wrikken Dec 12 '12 at 01:28
  • @Wrikken sorry, apache was not restarted. Now I can see the error. But this make me wonder: if we can set output_buffering = Off then why bother about PHP closing tag? Thanks. – Marcos Dec 12 '12 at 01:30
  • See [Headers already sent "Outbut buffering workaround"](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php#~workaround) and why it is amateurish. – mario Dec 12 '12 at 01:35
  • Those 2 have... not much to do with one another? How do you mean? (and about the last ending `?>` in a file, Zend actually believes we shouldn't put it there, and yes, you can omit the last `?>` in a file) – Wrikken Dec 12 '12 at 01:37
  • @Wrikken I mean that if we can set the output buffering off then omit the last `?>` is not necessary. But I have seen that the output buffering is just a workaround (in the link that @mario sent). – Marcos Dec 12 '12 at 01:42
  • .. I still do not see the connection....? Omitting the last `?>`is not necessary with or without ob buffering... ? – Wrikken Dec 12 '12 at 01:48

1 Answers1

0

It is not showing you an error because it is NOT! the function is

header(string,replace,http_response_code)

where string may be anything you wanna set as a header field:value. There isn't a list what can be used or what not. You can always have custom header fields.

check the manual - http://php.net/manual/en/function.header.php.

<?php
header('inappropriate stuff');
?>

try this and you wont be getting anything in header packet since php can't find a colon ':' as a separator inside the string which separates the header field from the value.

NOTE: If you plan to use it with session, session_start() must be the first function to run at the beginning of your execution.

Charles
  • 50,943
  • 13
  • 104
  • 142
Praveen Puglia
  • 5,577
  • 5
  • 34
  • 68