What is causing the "Cannot modify header information" warning in the PHP code for the logout function?

The "Cannot modify header information" warning in PHP typically occurs when there is output sent to the browser before PHP attempts to modify headers, such as using functions like header(). To solve this issue, you should ensure that there is no output (including whitespace) before calling header() function in your code.

<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit();
?>