What are the advantages of setting HTTP headers, such as HTTP/1.1 404 Not Found, in PHP scripts to handle errors?

Setting HTTP headers in PHP scripts allows for better control over the response sent to the client. By setting appropriate headers, such as HTTP/1.1 404 Not Found for error pages, you can provide more meaningful information to users and search engines. This can improve the user experience and help with SEO.

<?php
header("HTTP/1.1 404 Not Found");
echo "<h1>404 Not Found</h1>";
echo "<p>The page you are looking for could not be found.</p>";
?>