PHP: strefaphp.net
PHP: strefaphp.net



 
Czy odwiedziłeś już te strony? -
dodał: Vengeance

Opis artykułu dodano: 25-01-2005 14:09
Nie na każdym serwerze istnieje obsługa błędów, a gdy strona nie istnieje wyrzuca nas do strony dostawcy. Można temu zapobiec.
dodał: Dominium | autor: Dominium | czytano: 8286 razy

Inne materiały do artykułu

Własna obsługa stron z błędami
Tworzymy prosty plik o nazwie .htaccess o takiej treści:


Kod:

ErrorDocument 400 http://strona/error.php?e=400
ErrorDocument 401 http://strona/error.php?e=401
ErrorDocument 403 http://strona/error.php?e=404
ErrorDocument 404 http://strona/error.php?e=404
ErrorDocument 405 http://strona/error.php?e=405
ErrorDocument 406 http://strona/error.php?e=406
ErrorDocument 408 http://strona/error.php?e=408
ErrorDocument 410 http://strona/error.php?e=410
ErrorDocument 411 http://strona/error.php?e=411
ErrorDocument 414 http://strona/error.php?e=414
ErrorDocument 500 http://strona/error.php?e=500
ErrorDocument 503 http://strona/error.php?e=503



A następnie plik o nazwie error.php:


Kod:

<?php
switch ($_GET['e']) {
        case 
'401':
              echo
'<head>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<TITLE>Error 401</TITLE>
<LINK href="error/style.css">
</HEAD>
<body>
<div align="center">
  <center>
  <table border="0" width="510" height="240" cellspacing="0" cellpadding="0">
    <tr>
      <td width="510" height="1" valign="top">
        <h1 align="center">Error 401</h1></td>
    </tr>
    <tr>
      <td width="510" height="78" valign="top">
        <p align="center"><b>Brak Autoryzacji</b></td>
    </tr>
    <tr>
      <td width="510" height="24" valign="top">
        <font size="1"><center>Copyright &copy; 2004 by ZHP.pl<br>
All rights reserved</font></center></td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>'
;
           break;
        case 
'404':
              echo
'<HTML>
<head>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<TITLE>Error 404</TITLE>
<LINK href="error/style.css">
</HEAD>
<body>
<div align="center">
  <center>
  <table border="0" width="510" height="240" cellspacing="0" cellpadding="0">
    <tr>
      <td width="510" height="1" valign="top">
        <h1 align="center">Error 404</h1></td>
    </tr>
    <tr>
      <td width="510" height="78" valign="top">
        <p align="center"><b>Nie znaleziono strony o podanym adresie</b></td>
    </tr>
    <tr>
      <td width="510" height="24" valign="top">
        </td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>'
;
           break;
         case 
'403':
               echo
'<HTML>
<head>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<TITLE>Error 403</TITLE>
<LINK href="error/style.css">
</HEAD>
<body>
<div align="center">
  <center>
  <table border="0" width="510" height="240" cellspacing="0" cellpadding="0">
    <tr>
      <td width="510" height="1" valign="top">
        <h1 align="center">Error 403</h1></td>
    </tr>
    <tr>
      <td width="510" height="78" valign="top">
        <p align="center"><b>Brak Dostępu do tej czę&para;ci strony</b></td>
    </tr>
    <tr>
      <td width="510" height="24" valign="top">
        </td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>'
;
           break;
         case 
'500':
               echo
'<HTML>
<head>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-2">
<TITLE>Error 500</TITLE>
<LINK href="error/style.css">
</HEAD>
<body>
<div align="center">
  <center>
  <table border="0" width="510" height="240" cellspacing="0" cellpadding="0">
    <tr>
      <td width="510" height="1" valign="top">
        <h1 align="center">Error 500</h1></td>
    </tr>
    <tr>
      <td width="510" height="78" valign="top">
        <p align="center"><b>Bł&plusmn;d Wewnętrzny Servera.<br>Za utrudnienia Przepraszamy</b></td>
    </tr>
    <tr>
      <td width="510" height="24" valign="top">
        </td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>'
;
           break;
         default:
                 
header("location: index.php");
           break;
}
?>



I to by było na tyle. Teraz możemy sie cieszyc własną obsługą błędów. Plik error.php można dowolnie modyfikować.
PHP: strefaphp.net
wyślij email informacje forum download skrypty katalog kursy porady artykuły home współpraca reklama kontakt