To include the correct file and display the error page when an error occurs, I have the following code (very simplified):
$page = 'examplePage.php';
$page404 = '404.php';
if (file_exists($page))
{
require($page);
}
else if (file_exists($page404))
{
require($page404);
}
else
{
}
?>
Summarizing:
If I have a file, I include it.
If I do not have the file, I include the error file.
What if the error file also does not exist?
I would like it to display as the default error page of the browser .
I already achieved this in Internet Explorer by sending empty content with an HTTP error. The problem is that other browsers do not work the same way, they all display a blank page .
Is there any way to tell browsers to display their own error page? (not only 404, but all errors: 304, 500, etc.)
Thank.
: , , .
2:
$possiblePaths = array(
$urlPath,
D_ROOT.$urlPath,
D_PAGES.$urlPath.'.php',
D_PAGES.$urlPath.'/index.php',
$urlPath.'.php'
);
foreach ($possiblePaths as $possiblePath)
if (file_exists($possiblePath) && !is_dir($possiblePath))
{
if (!is_readable($possiblePath))
{
Response::setCode(403);
self::$filePath = self::getErrorPage(403);
}
else
self::$filePath = $possiblePath;
break;
}
if (self::$filePath === null)
{
Response::setCode(404);
self::$filePath = self::getErrorPage(404);
}
public static function _getErrorPage($code)
{
if (is_readable(D_ERRORS.$code.'.php'))
return D_ERRORS.$code.'.php';
else
{
if ($code >= 400)
Response::$dieResponse = true;
return null;
}
}
?>
:
<?php
if (self::$dieResponse)
{
self::$headers = array();
self::$content = '';
}
http_response_code(self::$code);
foreach (self::$headers as $key => $value)
header($key.': '.implode(';', $value));
echo self::$content;
?>
: , , .
IE:

, .
. .
, , Chrome :
