What is a potential method for determining if cookies are enabled in a browser using PHP?

To determine if cookies are enabled in a browser using PHP, we can set a test cookie and then check if it exists in subsequent requests. If the cookie exists, it means that cookies are enabled in the browser.

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

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