I have a PHP file that I want to execute at the beginning of each request. I specified it in the htaccess file:
php_value auto_prepend_file "alwaysrunthis.php"
The problem is that the value of this directive is executed in the context of the target script, and not in the context of the location of the .htaccess file. Thus, it works if the executable script is executed in the same directory as the preend file, but otherwise not.
I understand that I can use the absolute path, but this is not very portable. Is there any variable I can get in .htaccess to generate an absolute path at runtime?
The short answer is no.
Longs, , , .
, $_SERVER['DOCUMENT_ROOT'] var, , , switch/if-else.
$_SERVER['DOCUMENT_ROOT']
__FILE__ var realpath, / "preend", .
__FILE__
realpath
-prepend.phprequire_once(realpath(__FILE__) . '/prepend.php');
require_once(realpath(__FILE__) . '/prepend.php');
//:, __FILE__, , preend , , .