Possible Duplicate:
Reference - What does this symbol mean in PHP?
I'm making a web application that uses URL queries to access different parts of the application. I was looking for a solution to make an invalid query like index.php?page=dashboarrrd
display an error 404 message instead of a PHP error.
After some searching, I found that I could use something like the following to do the job:
if(!@include($fileName)){
@include("pageData/404.php");
}
And that makes sense, but I don't know why that works. I mean, what the heck does the @
before the include
mean? I totally understand include $filename;
but I need an explanation for @include ($fileName)
the code you really need is
$fileName = "pagedata/".basename($_GET['page']).".php";
if(is_readable($fileName)) {
include($fileName);
} else {
include("pagedata/404.php");
}
and @ has absolutely nothing to do here
@ is one of biggest delusions coming from lack of experience.
Ones who using it do expect only one kind of error, while in fact there can be many more. And to gag ALL possible messages to suppress only one of them is definitely like to throw out the child along with the bath.
There is a fundamental problem that makes such misunderstanding so widespread:
Most PHP users cannot distinguish three sides of error control:
Most of time in sake of [3] people mess with (1) and (2). While each of them require separate treatment:
is_readable()
in my code exactly for that. 404.php
is a good example of such user-friendly behavior. As for the system error messages, a user shouldn't be able to see them at all. Just turn display_errors
off and see - there is no use for the @ again!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With