...

View Full Version : PHP template won't redirect bogus pages to error 404



J&J
06-08-2005, 03:25 PM
A site I'm working on uses a php template called LAYOUT.php to call the html pages into it via the include("$page.html") statement.

All links are written like so:

<a href="LAYOUT.php?page=whatsnew">What's New</a>

Now, the error pages are specified in an .htacess file, for example:

ErrorDocument 404 http://www.domain.com/LAYOUT.php?page=404


Are you with me so far? My question now is, when linking to nonexistent (soon-to-be-made) pages, why does it display the blank template, instead of showing the 404 error page (http://sims2.jandjwebservices.com/LAYOUT.php?page=404)? Try this link (http://sims2.jandjwebservices.com/LAYOUT.php?page=whatsnew) for example.

Is there a way to make this work, even if it means ditching htaccess and using PHP instead?

delinear
06-08-2005, 03:38 PM
What kind of checking is in place to determine whether the page is blank or not? If you posted some of the code it might help to see where the script is going wrong.

J&J
06-08-2005, 03:54 PM
Here's the coding for LAYOUT.php. I've colored all PHP in blue for you:


<?php if ($page == "") {$page="home";} ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<base href="http://sims2.jandjwebservices.com/" target="_top" />

<title>Simply Irresistible!</title>

<link rel="shortcut icon" type="image/x-icon" href="http://sims2.jandjwebservices.com/favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://sims2.jandjwebservices.com/styles.css" />
<script type="text/javascript" src="http://sims2.jandjwebservices.com/headers.js"></script>
</head>

<body id="simply-irresistible">

<h1 class="replace" id="pageHdr">SIMply Irresistible! A FREE Sims 2 Fansite<span></span></h1>

<div id="container">
<div id="leftCol">

<!-- START CONTENT //-->
<div id="leftHdr"></div>
<div id="leftBody">
<?php @ include("$page.html"); ?>
</div>
<div id="leftEnd"></div>
<!-- END CONTENT //-->

<div id="footHdr"></div>
<div id="footBody">
<p><em>SIMply Irresistible!</em> <b>&copy;2005, All Rights Reserved Worldwide.<br />
Site designed &amp; maintained by <a href="http://www.jandjwebservices.com" target="_blank">J&amp;J Web Services</a>.</b><br />
<applet code='counter' codebase='http://jandjwebservices.com/v-web/counter'
width='94' height='20' alt="Counter">
<param name='counter' value='sims2'>
<param name='style' value='32'>
<param name='minsize' value='6'>
<param name='bgcolor' value='#ffffff'>
<param name='twoclicks' value='http://simply-irresistible.org'>
</applet>
</p>

<p><b>COPYRIGHT NOTICE &amp; DISCLAIMER</b><br />
<small>This website in its entirety is copyrighted to "SIMply Irresistible!" unless otherwise noted. Viewing of this website, downloading any files, and accessing its web pages signifies that you have read, understood, and agree to our <a href="LAYOUT.php?page=notice" target="_blank">copyright notice &amp; disclaimer</a>. Thank you for your compliance!</small></p>

<p>This site is not endorsed by or affiliated with Maxis, Electronic Arts, or its licensors.<br />
Trademarks are the property of their respective owners.<br />
Game content and materials copyright Electronic Arts Inc. and its licensors. All Rights Reserved.</p>
</div>
<div id="footEnd"></div>

</div><!-- end leftColumn //-->


<div id="rightCol">
<!-- START MENU //-->
<?php @ include("MENU.php"); ?>
<!-- END MENU //-->
</div><!-- end rightColumn //-->

</div><!-- end container //-->

</body>
</html>


Go to the site: click here (http://sims2.jandjwebservices.com/)

Then click on "What's New (http://sims2.jandjwebservices.com/LAYOUT.php?page=whatsnew) " at the bottom-righthand corner of the page. It shows an empty shell (blank template), instead of 404 page error.

delinear
06-08-2005, 04:16 PM
Hmm, well there's no checking in that code to determine if $page is actually a page that exists or not. Try adding something like this to the top of the script:

<?php if ($page == "") {$page="home";}
if(!file_exists($page . '.html')) {
header('Location: http://www.domain.com/LAYOUT.php?page=404');
}
?>

Fou-Lu
06-08-2005, 04:57 PM
Yep, the .htaccess files will search for errordocuments on 404 NOT FOUND. Key word, not found. The page is there, so it won't work for the .htaccess file. I'm not an apache .htaccess file kind of guy so it may be possible to do, but probably not worth your while.
Delinear's method is the best bet when it comes to a php solution for sure. Nice and simple, page not there, 404.
You keep beating me to all of these posts today ;)

delinear
06-08-2005, 05:13 PM
You keep beating me to all of these posts today ;)
Aww shucks, I try and leave all the tough ones for you :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum