Home  >  Article  >  Backend Development  >  Why can PHP output but the cookie can still be set successfully?

Why can PHP output but the cookie can still be set successfully?

WBOY
WBOYOriginal
2016-10-10 11:56:091013browse

<code><?php
echo 'some outputs';
var_dump(setcookie('hello', 'world')); // bool(true)</code>

Reply content:

<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

Why can PHP output but the cookie can still be set successfully?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn