If you set a cookie with an expires value equal to or older than the current system clock, it actually deletes the named cookie (if path or domain different, or if it is a โsafeโ cookie - none of them apply here).
It:
setCookie(cookie_names[i], 1, 0);
Forces this function to set a cookie with an instant expiration value, effectively deleting any cookie with this name.
To set a new cookie, use:
setCookie(cookie_names[i], 1, null);
which will force your code to set a session cookie - which is probably what you need.
Or use:
setCookie(cookie_names[i], 1, 1);
To set a cookie that expires in a day.
source share