What are some best practices for maintaining data integrity when redirecting with header() in PHP?

When redirecting with header() in PHP, it is important to ensure that data integrity is maintained by preventing any output before the header is sent. To achieve this, you can use ob_start() to buffer the output and ob_end_flush() to send the output only after the header is set.

ob_start();
// Perform any operations or calculations here
header("Location: new_page.php");
ob_end_flush();
exit();