RE: [PHP] Making your include files invisible (header() in if loop)
| From: | Peter Brown | Date: | Fri, 01 Feb 2002 04:57:19 +0000 |
| Subject: | RE: [PHP] Making your include files invisible (header() in if loop) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83062@lists.php.net to get a copy of this message | ||
I don't know if this is related but header() must be called before any
actual output is sent.
One way to resolve this is to use the ob_start() tag at the start of the
code, this turns output buffering on.
Mind you I am no expert and stand ready to be corected and berated.
Peter
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?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net