I delete the cookie file by the following action:

setcookie("non_reg_user", " ", time() - 30, "/"); 

Further down the code I have an if block that checks if cookies are deleted:

 setcookie("non_reg_user", " ", time() - 30, "/"); if (!isset($_COOKIE['non_reg_user'])) { echo "cookie is gone!"; } 

The problem is that if the block only works after 2 page reloads. How can you make the if block work during the first page load?

    1 answer 1

    In your case, without crutches - in any way.

    It is necessary to understand how cookies work, deleting cookies - comes in response from the server, but before that a cookie with your element came from the client. All that remains for you is to reset the array with handles.

     setcookie("non_reg_user", " ", time() - 30, "/"); unset($_COOKIE['non_reg_user']); 

    This is a crutch, but like this. You can find a normal one, or develop a class yourself that will do this, and it will look prettier.

    • thank you very much everything works - evseygames