What are common issues with setting and retrieving cookies in PHP?

Common issues with setting and retrieving cookies in PHP include not setting the cookie before any output is sent to the browser, not specifying the correct path or domain for the cookie, and not properly encoding or decoding the cookie values. To solve these issues, make sure to set cookies before any output is sent, specify the correct path and domain for the cookie, and use functions like `urlencode()` and `urldecode()` to properly encode and decode cookie values.

// Set cookie before any output
setcookie('cookie_name', 'cookie_value', time() + 3600, '/');

// Retrieve cookie value
$cookie_value = isset($_COOKIE['cookie_name']) ? $_COOKIE['cookie_name'] : '';

// Encode and decode cookie value
$encoded_value = urlencode($cookie_value);
$decoded_value = urldecode($encoded_value);