What are common pitfalls when using header('Location:..') to redirect in PHP and how can they be avoided?

Common pitfalls when using header('Location:..') to redirect in PHP include not calling the function before any output is sent to the browser, not using an absolute URL for the location, and not exiting the script after the redirect. To avoid these issues, make sure to call header('Location:..') before any HTML or text output, use an absolute URL for the location, and exit the script after the redirect.

<?php
// Make sure to call header() before any output
header('Location: http://www.example.com/new_page.php');
exit; // Exit the script after the redirect
?>