What are some best practices for handling redirection in PHP scripts that are included in the body?

When including PHP scripts in the body of a webpage, it's important to handle redirection properly to avoid header errors or unexpected behavior. One best practice is to use output buffering to capture any output before sending headers. This way, you can safely handle redirection without any issues.

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

// Your PHP code here

ob_end_clean(); // Clean (discard) the output buffer

// Perform redirection if needed
header('Location: new_page.php');
exit;
?>