DBGTN.com: [Return to the Previous Page]

• Tutorials: PHP: Custom 404 Page

PHP is short for Post Hypertext Peripheral Coding. It's a great programming language that lets you do many things never thought possible. You can change your layout without having to edit every single page of your site. It's not complicated to learn if you're familiar to SSI and it's very handy. Before you convert anything to PHP make sure your host supports PHP or else it won't work. Free web hosts such as: FreeWebsites.com, Geocities, Angelfire, etc. do not support PHP!

The code below lets you have your own custom 404 page not found error page.

<?php
$extension = ".html";
$link = "http://www.domain.com/$id$extension";
flush();
$fp = @fopen($link, "r");
if (!$fp) { include("404$extension"); }
else { fclose($fp); include("$id$extension"); }
?>

1st step: Change ".html" to the file extension you use(most people won't need to change this but some people preffer to use .txt or .htm for the files they include), change "http://www.domain.com" to your own domain name, and finally change "$id" to the string you use to call your html page (example: our site uses index.php?dbgt=page_here I would change $id to $dbgt).

2nd step: Place the modified code onto your index.php (or main.php, home.php, e.t.c.) where you would normally include your content file.

3rd step: Now create a page called "404.html" (or 404.txt for those of you who preffer it), this page will have your own message with images to display a custom 404 page.





[Return to the Previous Page]
[Return to the DBGTN homepage]