Auto prepend PHP file using htaccess relative to htaccess file

后端 未结 3 1171
清歌不尽
清歌不尽 2021-01-02 01:03

I used:

php_value auto_prepend_file \"file.php\"

in my .htaccess that is in public_html folder.

Now when

3条回答
  •  天涯浪人
    2021-01-02 02:04

    The file must be inside PHP's include_path. So you must either set the file's directory to be in the include_path inside php.ini, or do it in the .htaccess with a php_value statement.

    php_value include_path ".:/path/to/file_directory"
    php_value auto_prepend_file "file.php"
    

    If you use the above method in .htaccess, be sure to copy the include_path from php.ini in and add the :/path_to/file_directory so you don't lose any already needed includes.

    Alternatively, just add :/path/to/file_directory to include_path directly in the php.ini

    Update

    If you cannot modify the include_path, you might try specifying a relative path to the auto_prepend_file. This should work since the file path sent is processed identically as if it was called with require():

    php_value auto_prepend_file "./file.php"
    

提交回复
热议问题