What are the potential issues with using header() for redirection in PHP?

Using header() for redirection in PHP can cause potential issues such as headers already being sent, leading to a "Cannot modify header information" error. To solve this, make sure that no output is sent before calling header() by placing it at the top of the script before any HTML or whitespace.

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

// Your PHP code here

header("Location: https://www.example.com");
exit();
ob_end_flush(); // Flush the output buffer
?>