Forum Moderators: coopster

Message Too Old, No Replies

is an include error-echo possible?

         

StickeR

9:58 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



So far everything works well, however, when someone tries to 'hack' my site (or in case of a faulty link), things will go completely wrong.
I am including the pages as such:

if(isSet($page)){ include("pages/".$page.".php");
}else{
include("news.php");
}

Whenever things go wrong, it'll go like this:

Warning: main(pages/ohoh.php): failed to open stream: No such file or directory in /home/mememe/public_html/index.php on line 69

Warning: main(pages/ohoh.php): failed to open stream: No such file or directory in /home/mememe/public_html/index.php on line 69

Warning: main(): Failed opening 'pages/ohoh.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/mememe/public_html/index.php on line 69

Is there any way to make an errorthing for this?
Like that it just echos 'Error', instead of the php-warnings?

As always many thanks in advance

ironik

10:15 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



Yep, you just have to test if the file exists before you include it:


if(isset($page)){
if (file_exists('pages/' . $page . '.php')) {
include("pages/".$page.".php");
} else {
echo 'File: pages/' . $page . '.php does not exist!';
}
}else{
include("news.php");
}

StickeR

10:52 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



Yes, that's exactly what I had in mind, I didn;t know there was a file_exists command..

So thank you VERY much :) thumbs up!