How can PHP be used to prevent any output before performing a redirection or forwarding action?

To prevent any output before performing a redirection or forwarding action in PHP, you can use the ob_start() function to buffer the output. This function will start output buffering, which will store any output generated by PHP in memory instead of sending it to the browser. Once the redirection or forwarding action is complete, you can then use ob_end_clean() to discard the buffered output and prevent it from being sent to the browser.

<?php
ob_start();

// Perform any necessary PHP logic before redirection

header("Location: new_page.php");
exit();

ob_end_clean();
?>