What is the best practice for setting cookies in PHP to avoid header modification warnings?

When setting cookies in PHP, it's important to make sure that no output has been sent to the browser before calling the `setcookie()` function, as it sends HTTP headers to set the cookie. If any output has been sent, PHP will generate a warning like "headers already sent". To avoid this issue, you can use output buffering to capture any output before setting cookies.

<?php
ob_start(); // Start output buffering

// Set cookies here
setcookie("cookie_name", "cookie_value", time() + 3600, "/");

ob_end_flush(); // Flush the output buffer
?>