PDA

View Full Version : How to design 404 error Page in PHP?



ayishabanu
03-07-2013, 11:07 AM
How to design innovative 404 error page in PHP?Thanks in advance:o

rosterfedrik
05-18-2013, 08:02 AM
In PHP error handling is typically done through you .htaccess file. In .htaccess file has all 404 errors We can include .htaccess file in PHP code then re-direct all 404 errors to a 404.php page. I hope Ayishabanu your problem is solved.

Akshay_M
02-23-2023, 02:12 PM
To create a PHP version of custom 404 error page open any text editor of your choice and insert the following code and save it as 404page.php or any other name of your choice but the extension must be .php because here 404 error page is being demonstrated with PHP technology.

<?php
header("HTTP/1.0 404 Not Found");
?>
<html>
<head>
<title>404 Error - Page Not Found</title>
</head>
<body>404 Error - Page Not Found!</body>
</html>
Following things you must remember while creating a 404 error page.

You must specify the 404 HTTP response header in your custom 404 error page else it would be treated as a normal page and 200 OK response will be sent to client browser.
The header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. In above sample error page the header that starts with the string "HTTP/" (case is not significant) will be used to figure out the HTTP status code to send. Here we have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive - will be explained shortly), we make sure that our script generates the proper status code.
The above page is just for demonstration, you can beautify your custom 404 error page as you like and add more relevant content depending upon how much information you want to convey to your audience.