How can PHP developers ensure that custom error pages are displayed correctly for different types of errors or incorrect URLs?
To ensure that custom error pages are displayed correctly for different types of errors or incorrect URLs, PHP developers can use the `header()` function to set the appropriate HTTP response code and then include the custom error page content. By setting the correct response code, the browser will display the custom error page instead of the default server error page.
<?php
// Check for specific error conditions
if ($error_condition) {
header("HTTP/1.0 404 Not Found");
include("404_error_page.php");
exit();
} elseif ($another_error_condition) {
header("HTTP/1.0 500 Internal Server Error");
include("500_error_page.php");
exit();
} else {
// Normal page content
}
?>