How can cookies be effectively used to determine error types in PHP?

Cookies can be effectively used to determine error types in PHP by setting a specific cookie value when an error occurs, and then checking for this cookie value in subsequent requests to identify the error type. This can be useful for debugging and logging purposes, allowing developers to track and handle different types of errors more efficiently.

// Set a cookie with the error type
setcookie('error_type', 'database_error', time() + 3600);

// Check for the cookie value to determine the error type
if(isset($_COOKIE['error_type'])) {
    $error_type = $_COOKIE['error_type'];
    // Handle the error based on the error type
    if($error_type == 'database_error') {
        echo 'Database error occurred';
    }
}