What are some best practices for using header("location: index.php") in PHP to avoid problems with script execution?

When using `header("location: index.php")` in PHP, it is important to ensure that there is no output sent to the browser before this header function is called. This is because headers must be sent before any output is generated. To avoid problems with script execution, it is recommended to use `ob_start()` and `ob_end_flush()` functions to buffer the output and prevent any premature output.

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

header("Location: index.php");
ob_end_flush();
exit;
?>