Why does adding a space before the PHP opening tag cause issues with header modification?

Adding a space before the PHP opening tag causes issues with header modification because any output, including whitespace, sent before the header() function is called will prevent the headers from being modified. To solve this issue, ensure that there is no whitespace or output before the PHP opening tag in order to successfully modify headers.

<?php
ob_start();
// Your PHP code here
header("Location: https://www.example.com");
ob_end_flush();
exit;
?>