...

View Full Version : Implementing error 404 element in php



JamieR
10-17-2004, 11:53 AM
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];
}

include($page);
?>
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:

fci
10-17-2004, 12: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..

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum