What are the best practices for setting cookies in PHP to ensure they are properly stored and retrieved?

When setting cookies in PHP, it is important to ensure they are properly stored and retrieved by setting the correct parameters such as expiration time, path, and domain. It is also recommended to sanitize the data being stored in cookies to prevent any security vulnerabilities.

// Set a cookie with proper parameters
setcookie("cookie_name", "cookie_value", time() + 3600, "/", "example.com", true, true);