Auto prepend PHP file using htaccess relative to htaccess file

后端 未结 3 1163
清歌不尽
清歌不尽 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 01:49

    In your .htaccess

    php_value auto_prepend_file /auto_prepend_file.php
    php_value auto_append_file /auto_append_file.php
    

    Next create 2 files in root

    1) /auto_append_file.php

    $appendFile = $_SERVER['DOCUMENT_ROOT'] . '/append.php';
    require_once($appendFile);
    

    2) /auto_prepend_file.php

    $prependFile = $_SERVER['DOCUMENT_ROOT'] . '/prepend.php';
    require_once($prependFile);
    

    Now it should work on local and live servers irrespective of physical path or website providing each of your websites use the same filenames append.php and prepend.php.

提交回复
热议问题