View Full Version : Implementing error 404 element in php

10-17-2004, 12:53 PM
I have this PHP script which i custom which i customised for my needs:
$id = $_REQUEST["id"];

$arrFile[index] = "index.php";
$arrFile[contact] = "contactme.php";
$arrFile[poll] = "poll.php";

if($id!="") {
$page = $arrFile[$id];
} else {
$page = $arrFile[1];

It gives me an array of various filenames which i can use in conjunction with linked html pages.
What I want to know is: is it possible to implement a element into this script to let me use a 404 error page, like I do with the rest of my site when a "not found" error occurs?
i.e. if someone tries to call /test.php?id=phpscripts, i would get this error:
"Warning: main(): Failed opening '' for inclusion (include_path='.:/usr/local/lib/php') in /home/www/MYSITE
/TEST.PHP on line 14" I don't want this error to occur, i want a standard 404 error page to occur. I have tried using .htaccess for this, which i used for the other error pages but to no avail.
any ideas? :confused:

10-17-2004, 01:03 PM
make sure the array key exists in the array.. otherwise make it 404

if (array_key_exists($id, $arrFile)) {
} else {
//404.. header('Location: http://www.domain.com/404.html');

since you're sending headers.. that should go at the top of the page before any HTML output..

10-18-2004, 11:04 AM
do i put it below the array code?