How can PHP be used to check if cookies are enabled for a visitor?

To check if cookies are enabled for a visitor using PHP, you can set a test cookie and then check if it exists when the page is reloaded. If the test cookie is present, it means that cookies are enabled for the visitor. If the test cookie is not present, it indicates that cookies are not enabled.

<?php
// 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 for this visitor.';
} else {
    echo 'Cookies are not enabled for this visitor.';
}
?>