What is a common pitfall when using the header function in PHP to redirect users?

A common pitfall when using the header function in PHP to redirect users is that headers must be sent before any output is sent to the browser. If there is any output (even whitespace) before the header function is called, it will result in a "headers already sent" error. To solve this issue, make sure to call the header function before any output is generated in the script.

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

// Redirect users
header("Location: https://www.example.com");

// Flush output buffer
ob_end_flush();