0

I wrote a PHP program, I use session_start() and header() functions, I know I should use this functions before I sending anything to client. it's ok, but for test I send a test message to client with echo "test"; before using header(), but I didn't get any error and header function work without any problem !

In previous versions of PHP at this time I will got a message like :

Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:22) in /some/file.php on line 60

I wan't to know why I didn't get any error message ?!

My php version is 5.3.1 and error_reporting is on E_ALL

MajAfy
  • 3,007
  • 10
  • 47
  • 83
  • @LinusKleen Yes, As I said `header()` will work, `session_start()` will work too. I use header for redirect to a page `header("Location: mypage.php");` – MajAfy Nov 22 '12 at 08:24
  • are the file.php UTF-8 encode? – A1Gard Nov 22 '12 at 08:27
  • @MahdiParsa Yes, encoding is UTF-8 – MajAfy Nov 22 '12 at 08:33
  • @MahdiParsa without BOM, but this is not my question, my question is why I didn't get any error, I should receive an error when I send a parameter to client before using `header()` – MajAfy Nov 22 '12 at 08:43

3 Answers3

1

You don't see the error because
a. output buffering is on
b. the server ignores your error_reporting function because something else instructs it otherwise run phpinfo(); and see what it says there about output buffering and about error_reporting.

Alex
  • 11,479
  • 6
  • 28
  • 50
  • thanks for your response, output_buffering >> no value and output_handler>>no value and error_reporting >> 30719 – MajAfy Nov 22 '12 at 08:32
  • `php.ini` settings do not supercede settings of `error_reporting()` – Linus Kleen Nov 22 '12 at 08:34
  • @LinusKleen Those of `.htaccess` does or when working with IIS sapi - it does. @MajAfy do you see other errors ? like notices for undefined variables ? – Alex Nov 22 '12 at 08:37
  • @LinusKleen in `php.ini` the `error_reporting` is `E_ALL` : `error_reporting = E_ALL` – MajAfy Nov 22 '12 at 08:37
  • @Alex Yes, another errors (Warning, Fatal, Notice and ...) will show – MajAfy Nov 22 '12 at 08:38
  • Than, apparently, there is no error in your code ;) Could you put your code on pastebin so we could examine it? + I suggest you try a simple, faulty case, such as – Alex Nov 22 '12 at 08:47
0

This might be possible because you write into an output buffer (ob_start) which doesn't actually return anything to the client until you explicitly flush the buffer (ob_flush or ob_end_*) or the script ends.

The fact that you can't send headers after you begun writing the body part of your HTTP response is not a php but a HTTP protocol limitation, so this cannot be version specific either.

Many frameworks like the Zend Framework use output buffers so a developer doesn't need to care about the order.

Michel Feldheim
  • 17,625
  • 5
  • 60
  • 77
0

I found the problem, I don't use any FrameWork.

the problem was error_reporting('E_ALL');

I wrote this code on first of my program, and so PHP didn't return any errors ! I deleted this line and I get the errors !

This is kidding because this line said to PHP to show ALL errors ! I don't know why PHP don't show any errors.

MajAfy
  • 3,007
  • 10
  • 47
  • 83