0

I am trying to add a cookie in my add_cookie.php file like so:

<?php

setcookie("TestCookie", 'epic_test', time()+3600);
exit('cookie set');

But when accessing https://my-site.com/add_cookie.php I do see the "cookie set" text, but the cookie is not in fact set. Why is that? This code is straight from the documentation :)

I have also tried adding this code to functions.php file of my theme and the result is the same.

1
  • is this a WordPress question? No WordPress code is executed if you go directly to a PHP file this way, this looks like a general PHP question that could be asked on stackoverflow. Be sure to include details of how you are checking/testing the cookie is set, and if your server/host is applying caching
    – Tom J Nowell
    Commented Jul 28 at 18:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.