Making your include files invisible (header() in if loop)
| From: | qartis | Date: | Fri, 01 Feb 2002 04:50:01 +0000 |
| Subject: | Making your include files invisible (header() in if loop) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83061@lists.php.net to get a copy of this message | ||
I wanted to hide the existance of my include files by making them
'invisible': give a 404 error when requested. This worked, but the files
that were including were obviously 404ing too. So I decided to use $PHP_SELF
and check whether the script's PHP_SELF was it's filename, which would mean
that it was being accessed directly, as opposed to being included. I tried
this code:
(include.php)
<?
$string = "include";
$container = "$PHP_SELF";
if(strstr($container,$string)) {
header("HTTP/1.0 404 not found");
exit;
}
?>
at the top of the include files, but it wasn't working. Change the header()
to an echo and test it. It echoed. So it's a problem with the header(). I
tried this:
<?
header("HTTP/1.0 404 Not Found");
?>
and it worked perfectly. Can header() not be in an if loop or something like
that?