How can headers_list() and headers_sent() be used to debug PHP code?

To debug PHP code related to headers, you can use the `headers_list()` function to retrieve a list of headers that have been sent, and the `headers_sent()` function to check if headers have already been sent to the browser. This can help identify issues such as headers being sent too late in the script or being sent multiple times.

// Check if headers have been sent
if (headers_sent()) {
    die("Headers have already been sent.");
}

// List all headers that have been sent
$headers = headers_list();
foreach ($headers as $header) {
    echo $header . "<br>";
}