I'm using a auto_prepend_file directive in my .htaccess, like so :
php_value auto_prepend_file "includes/init.php"
This is my folder's structure :
/php
/css/main.css
/includes/init.php
/lib/functions.php
index.php
.htaccess
This is working fine for all the files in the root, such as index.php. However, it will not work for all the files that are not in the root, such as functions.php that is in the lib folder.
I am getting the following error :
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'includes/init.php'
(include_path='.;C:\xampp\php\PEAR') in Unknown on line 0
It seems like it can't find the file where it should be, which makes sense.
I'm trying to point to the root of my project, but I don't know how I can do that within the .htaccess.
I tried changing my .htaccess line to the following :
#Same problem
php_value auto_prepend_file "/includes/init.php"
#Won't work for any page now
php_value auto_prepend_file "/php/includes/init.php"
What do I need to put in my .htaccess so that the path always work, no matter where I am in the hierarchy?
Either you specify a relative path, as you do now, but then you'd need to override it in every folder - or you need to specify a real absolute path, from the root of the filesystem, like:
php_value auto_prepend_file "/var/www/mywebsite/php/includes/init.php"
In this case it will always work as it is absolute.
If you have trouble determining the absolute path, just echo __DIR__ in one of your PHP files - it will show the absolute path it is currently in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With