What is the best practice for checking the persistence of cookies in PHP?

When working with cookies in PHP, it is important to check their persistence to ensure they are being set correctly and are not expiring prematurely. One way to do this is by setting a longer expiration time for the cookie and verifying that it persists across multiple page loads.

// Set a cookie with a longer expiration time
setcookie("test_cookie", "value", time() + 3600);

// Check if the cookie is set and display a message
if(isset($_COOKIE['test_cookie'])) {
    echo "Cookie is persistent!";
} else {
    echo "Cookie has expired or not set.";
}