PHP Input And Error Page Help Please....

Naz20xl

Limp Gawd
Joined
Jul 24, 2002
Messages
459
I am using PHP input on my site to manage the pages easier, and I want ALL 404 errors to go to this custom 404 page I made. Now I am saying ALL because I made a .htaccess file and that redirects the 404 error to the custom one I made, but when its a PHP error, it goes to the original PHP error line. Here is the code I am using. Should I jus be able to add another else go to 404.php (my custom 404 error page)? Thanks for the help in advance guys.

Code:
<?php if($id == "") { include("headlines.php"); include("news/news.php"); } else { include("$id.php"); }?>
 
are you saying if there's a php 'error', does that mean if someone entered an invalid id?, you want it to act as if it were a 404?

you should be able to do something like what you said
Code:
<?php
if($id == "") { 
    include("headlines.php");
    include("news/news.php");
} elseif makeAFunctionToValidateID($id) {
      ---or---
} elseif file_exists("$id.php") {
    include("$id.php");
} else {
    include("404.php");
?>
also, you may want to use 'require' instead of 'include' depending on how it all works for your particular site.
 
Thanks for the help Tim, I saw what you did with your code and saw something on Google, that also gave me an idea, here is what I came up with for anyone else who is interested:

Code:
<?php

$id = $HTTP_GET_VARS['id'];
$extension = "php";
if ( !$id || $id == "" )
{
   include "headlines.php"; include "news/news.php";
}
else if ( file_exists( "$id.$extension" ) )
{
  include "$id.$extension";
}
else
{ include "errors/404.php"; }
?>

Thanks again Tim.
 
i'm not entirely sure if it makes a difference but i personally like to use isset() to see if a variable exists instead of !$var so i would do
Code:
$id = (isset($HTTP_GET_VARS[id])) ? $HTTP_GET_VARS[id] : "";
if you're not familiar with that syntax, it's equivalant is
Code:
if (isset($HTTP_GET_VARS[id])) {
    $id = $HTTP_GET_VARS[id];
} else {
    $id = "";
}
then for your first if statement, it would just be if ($id == "")
 
Back
Top