What role does the $_COOKIE superglobal play in handling cookies in PHP?

The $_COOKIE superglobal in PHP is used to retrieve values stored in cookies that have been sent to the server. It allows developers to access and manipulate cookie data within their PHP scripts. To handle cookies effectively, developers can use the $_COOKIE superglobal to access, modify, and delete cookie values as needed.

// Retrieve a cookie value using the $_COOKIE superglobal
$cookieValue = $_COOKIE['cookie_name'];

// Set a new cookie value using the setcookie function
setcookie('new_cookie_name', 'new_cookie_value', time() + 3600, '/');

// Delete a cookie by setting its expiration time to a past value
setcookie('cookie_name_to_delete', '', time() - 3600, '/');