What best practices should be followed when setting and updating cookies in PHP?

When setting and updating cookies in PHP, it is important to follow best practices to ensure security and proper functionality. This includes setting an expiration time for the cookie, specifying the path to restrict where the cookie is accessible, and using secure and HTTPOnly flags to prevent certain types of attacks.

// Set a cookie with an expiration time of 1 hour, accessible only on the current path, and with secure and HTTPOnly flags
setcookie("cookie_name", "cookie_value", time() + 3600, "/", "", true, true);