Re: Globally runnable PHP script
| From: | Philip Hallstrom | Date: | Tue, 17 Oct 2000 21:32:10 +0000 |
| Subject: | Re: Globally runnable PHP script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20717@lists.php.net to get a copy of this message | ||
>> In ASP there is global.asa, in CFML there is application.cfm, what is the
>> equivalent in PHP?
>>
>> In other words, is there a special file I can execute before the accessed
>> PHP file is parsed.
>
>Sure, you can set any file up to be parsed before a script (And after, for
>that matter).
>
>Check out auto_prepend_file
>
>http://www.php.net/manual/html/configuration.html#ini.auto-prepend-file
What's really nice is you can set auto_prepend_file to point to a file with the
following contents and then you can put auto_prepend.php files in any directory
you want and include directory specific stuff. Kind of like .htaccess files.
It's a little slower, but it sure is nice...
<?php
$G[sites_dir] = "/local/www/sites";
$G[base_dir] = $G[sites_dir] . "/foo.com";
$G[htdocs_dir] = $G[base_dir] . "/htdocs";
#
# Loop through all the directories specified in the URL
# and include any files named "auto_prepend.php.
#
$_dirs = split("/", $PHP_SELF);
for( $_i=0; $_i < count($_dirs); $_i++ ) {
$_dirPiece .= "/" . $_dirs[$_i];
if( $_dirPiece == "/" ) {
$_dirPiece = "";
}
$_file = $G[htdocs_dir] . $_dirPiece . "/auto_prepend.php";
if( file_exists($_file) ) {
include($_file);
}
}
?>