php setcookie is working after output without ob_start

20 views Asked by At

php version is:

PHP 7.2.24-0ubuntu0.18.04.7 (cli) (built: Oct  7 2020 15:24:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.7, Copyright (c) 1999-2018, by Zend Technologies

my code is :

error_reporting(E_ALL);
ini_set("display_errors", 1);
echo 'some random output ';
$adminCookie = "emFrYXRfZWxtX3JvYm90";
setcookie("admin", $adminCookie, time()+3600*3000, "/");

i was expecting an error because the cookie goes to header section and the data cannot be sent before it.

otherwise it would give an error like:

Warning: Cannot modify header information - headers already sent by (output started at /location/to/script.php) in /location/to/script.php on line x

but the code works fine and no errors being displayed! and the cookie is added to the browser after inspecting with chromes built-in tool. is ob_start() on by default on php 7.2.24-0ubuntu0.18.04.7 ?

0

There are 0 answers