Home > Backend Development > PHP Tutorial > 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
Release: 2016-10-10 11:56:09
Original
1033 people have browsed it

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

Reply content:

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

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?

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template