Skip to content
PHP Logo

Are there any potential workarounds to detect if cookies are enabled in PHP?

To detect if cookies are enabled in PHP, one common workaround is to set a cookie and then check if it exists on the next page load. If the cookie exists, then cookies are enabled. If the cookie does not exist, then cookies are likely disabled.

php
// Set a cookie
setcookie('test_cookie', 'test', time() + 3600);

// Check if the cookie exists
if(isset($_COOKIE['test_cookie'])) {
    echo 'Cookies are enabled.';
} else {
    echo 'Cookies are disabled.';
}