Forum Moderators: coopster

Message Too Old, No Replies

help testing if a file exists

         

electricocean

12:07 am on Apr 18, 2005 (gmt 0)

10+ Year Member



HI,
I was wondering how to make a script that makes sure the include file exists with this code that changes the include file when the url has
?pageid=x string.

my code: (Sorry I am posting so much about this script. I am just debugging it.)

<?php
$path = "includes";
$PageID = $_GET["pageid"];
if ($pageid=="")
{
include('includes/intro.inc');
}
if(isset($PageID))
{
if (! file_exists($filename))
print "<p align=\"center\"><font size=\"6\">Sorry, Page Not Found</font><br>Error 404</p>";

$filename = "$path/${PageID}.inc";
include($filename);
}
?>

The bold print looks right but it doesn't work. The text is written on every page. It has taken over the top of every page so every page is an error with the?pageid=x extension.

How should I fix this and make the text appear only when the page cannot find the include file suggested and will not show the php errors sayong it cannot find it?

thanks,
electricocean

AlexK

3:51 am on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is the quoted section your exact code? If so, you are testing for the existence of
$filename
before you have set it.

Put

error_reporting( E_ALL );
at the top of your code and it will warn you on all un-initialised variables (very useful when testing).