What are some alternative methods for redirection in PHP besides using the header function?

When redirecting in PHP, an alternative method to using the header function is to use JavaScript to perform the redirection. This can be achieved by outputting a small script that changes the window location to the desired URL. This method can be useful in scenarios where headers have already been sent or if you want to provide a smoother transition for the user.

<?php
// Redirect using JavaScript
echo '<script>window.location.replace("http://www.example.com");</script>';
?>