What best practices should PHP developers follow when implementing automatic redirection using the header() function in PHP?

When implementing automatic redirection using the header() function in PHP, developers should ensure that no output has been sent to the browser before calling the header() function. This is because headers must be sent before any actual output is sent to the browser. To prevent any output, developers can use ob_start() and ob_end_flush() functions to buffer the output.

<?php
ob_start();
// your PHP code here

// Redirect to a new page after 3 seconds
header("refresh:3;url=destination.php");

ob_end_flush();
?>