Salve a tutti
Sto imparando il php leggendo un libro.
Adesso sono al capitolo della gestione degli errori.
Nel libro si consiglia di aprire il file httpd.cong di apache, scommentare e modificare le righe riguardanti le azione da eseguire in caso di errore. Ecco il risultato finale:
# Some examples:
ErrorDocument 400 /error.php?400
ErrorDocument 401 /error.php?401
ErrorDocument 403 /error.php?403
ErrorDocument 404 /error.php?404
ErrorDocument 500 /error.php?500
#
Unico problema e che non viene detto dove deve stare la pagina error.php
io ho provato a mettarla nella cartella htdocs, nella cartella etc e anche nella cartella radice-principale di lamp.
nessuno cambiamento, nemmeno dopo aver riavviato il server.
ecco il codice di error.php
<html>
<head>
<title>Pagina di errore personalizzata</title>
</head>
<body>
<?php
switch ($_SERVER['QUERY_STRING']) {
case 400:
echo '<h1>Bad Request</h1>';
echo '<h2>Error Code 400</h2>';
echo '
The browser has made a Bad Request.</p>';
break;
case 401:
echo '<h1>Authorization Required</h1>';
echo '<h2>Error Code 401</h2>';
echo '
You have supplied the wrong information to access a secure resource.</p>';
break;
case 403:
echo '<h1>Access Forbidden</h1>';
echo '<h2>Error Code 403</h2>';
echo '
You have been denied access to this resource.</p>';
break;
case 404:
echo '<h1>Page Not Found</h1>';
echo '<h2>Error Code 404</h2>';
echo '
The page you are looking for cannot be found.</p>';
break;
case 500:
echo '<h1>Internal Server Error</h1>';
echo '<h2>Error Code 500</h2>';
echo '
The server has encountered an internal error.</p>';
break;
default:
echo '<h1>Error Page</h1>';
echo '
This is a custom error page...</p>';
}
echo '
Contact the system administrator if you feel this to be in error.</p>';
$now = (isset($_SERVER['REQUEST_TIME'])) ? $_SERVER['REQUEST_TIME'] : time();
$page = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : 'unknown';
$msg = wordwrap('A ' . $_SERVER['QUERY_STRING'] . ' error was encountered on ' . date('F d, Y', $now) . ' at ' . date('H:i:sa T', $now) . ' when a ' . 'visitor attempted to view ' . $page . '.');
mail('admin@example.com', 'Error from Website', $msg);
?>
</body>
</html>

Rispondi quotando