I have a php file add_cookie.php
that is set up like so:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$cookie_name = "testCookie";
$cookie_value = "cookieValue";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
echo "Headers sent by the server:<br>";
print_r(headers_list());
As far as I understand, the website does send the headers since the headers_list()
returns: Array ( [0] => Set-Cookie: testCookie=cookieValue; expires=Thu, 29-Aug-2024 21:08:20 GMT; Max-Age=2592000; path=/ )
ande adding a location header does also redirect to another page, but the cookie header seems to be ignored by the browser as it is nowhere to be found. Why does that happen?
The website is on WordPress, but I don’t want to import anything in this file. I am aware of add_action('init', ...)
.