This is contrary to my current knowledge of php and http ... How so?


$file='';$line=''; echo headers_sent($file,$line); echo " file = $file ; line = $line"; setcookie('sdfsdf',234); 


 file = ; line = 0 

And the most interesting: Cook is installed !

For those who did not understand: the cookie was established AFTER the withdrawal began. Is this new php stray, or wtf?

upd: PHP Version 5.3.3

  • the essence of the problem is different;) - thunder
  • Aha came later) - BiMaWa

1 answer 1

Really strange, at first glance, behavior. but! Inside pkhp there is a buffering, therefore cookies were put faster, than buffer was filled. There is an assumption that the setting in php.ini is responsible for this:

 output_buffering = 4096 

Because if you add such a piece before displaying cookies:

 $file='';$line=''; echo headers_sent($file,$line); echo " file = $file ; line = $line"; for ($i = 1; $i < 500; ++$i) echo 'Hello world!'; echo "<br/>"; setcookie('sdfsdf',234); var_dump($_COOKIE); 

it will be the expected Headers already set... because there will be more data than 4096 specified in the default settings.

Zzyzh empirically found that this is the case;)

 for ($i = 1; $i < 4000; ++$i) echo 'H'; 

here the cookies will be set, set the counter limit more by a few units (it is necessary to calculate how much, taking into account the other outputs), so that the buffer is filled and the output is realized before the cookies.

  • Yes, really, checked. - kanaris
  • Hmm ... Funny observation ... That's for sure, "an even number of errors gives the right result" ...) - Indifferent