Simple answer is PHP get's executed first. And no you can't change this.
You have basic 3 solutions:
- Set the cookie with PHP and read it with PHP.
- Set the cookie with JS and read it with JS.
- Set the cookie with PHP and read it with JS.
Note that if setting the cookie using PHP, you cannot output anything before it. Otherwise you will get a "header's already sent" error.
PHP.net - setcookie
Just to add another 2 cents, if you want to delete a cookie, set the cookie to an expiry time that has already occured.
“The best thing about a boolean is even if you are wrong, you are only off by a bit.”