0

Currently in my PHP coding I have to put include($_SERVER['DOCUMENT_ROOT']"./ in front of every file path in my web code. I previously asked and discovered I could set include_path. I tried setting this in both .htaccess and the .conf for the virtual host, but it just fails out and doesn't work/load the include.

Code: this is in the vhost .conf file:

<IfModule mod_php7.c>
    php_value include_path ":/var/www/testdomains/domain-test1.local/php"
    php_admin_flag engine on
</IfModule>

(I've tried putting this outside the IfModule area with no success.

My .php file on the webserver:

<?php require  "/authcheck.php"  ?>

What am I doing wrong?

3
  • 1
    You don't need an include_path to require other php-files in the same directory. If you have e.g. an index.php and a authcheck.php in the same directory just remove the leading slash like <?php require "authcheck.php" ?>. You need an include path to make files available that are not in the document-root of the webserver.
    – codeneuss
    Apr 4, 2019 at 6:08
  • If you want to include a file relatively from the file that does the including, use require __DIR__ . '/path/to/the/file.php'; - The __DIR__ -constant contains the absolute path to the file it's written in, which will make it work even if you include this file from another file, in another location. Apr 4, 2019 at 6:14
  • I'm trying to clean up code and the include_path seemed like the best way to do that. Either way, I'd rather be able to just include the headers and additional info without having to worry about relative paths and just write everything based on the Document Root. Is the code I've included above just not possible? Apr 4, 2019 at 16:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.