Home > Article > Backend Development > Why can PHP output but the cookie can still be set successfully?
<code><?php echo 'some outputs'; var_dump(setcookie('hello', 'world')); // bool(true)</code>
<code><?php echo 'some outputs'; var_dump(setcookie('hello', 'world')); // bool(true)</code>
It’s mentioned in the manual
Cookies are part of the HTTP headers, so the setcookie() function must be called before other information is output to the browser.
But PHP will enable output_buffering by default