What security considerations should be taken into account when setting cookies in PHP, especially in regards to the $secure and $httpOnly parameters?

When setting cookies in PHP, it is important to consider security measures to protect sensitive information. The $secure parameter should be set to true to ensure that the cookie is only sent over HTTPS connections, preventing interception by malicious parties. Additionally, the $httpOnly parameter should be set to true to prevent client-side scripts from accessing the cookie, reducing the risk of cross-site scripting attacks.

// Set a secure and HTTP-only cookie in PHP
setcookie("cookie_name", "cookie_value", time() + 3600, "/", "example.com", true, true);