Conditional Include
| From: | Andreas Brunschweiler | Date: | Wed, 17 Mar 2004 09:33:35 +0000 |
| Subject: | Conditional Include | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-180660@lists.php.net to get a copy of this message | ||
Hello
When I want to include a php file only conditionally, I use include instead of require. At the moment I am trying to solve the following problem. I haven't found anything in the news archive, perhaps I searched with the wrong phrase...
----code snippet-----
<?php
$includefiles=1;
if(...) {
... //some nested if statements.
... //in some cases $includefiles is set to 0
}
if($includefiles==1) {
include('incfile.php');
}
?>
----end code-----
In this code, the include file is always parsed, even if $includefiles is set to 0. Even the files which are 'required()' inside incfile.php are parsed (observed with the program Filemon, which registers file access). I tried various ways to nest the if statements, but none helped. Any suggestions to have incfile.php parsed only if needed?
I am using PHP Version 4.3.4 as Module, Apache/2.0.48, on Windows 2000.
Thanks a lot for any suggestions!
Andreas