How To Include a PHP File Site-wide Using .HTACCESS or other methods

前端 未结 5 896
一生所求
一生所求 2020-12-10 05:23

I want to include my PHP file googleanayltics.php on every page on my webserver that is a .php or .html document

I would like to know:<

5条回答
  •  醉梦人生
    2020-12-10 06:06

    EDIT: Only now I see what you actually wanted (was hidden due to formatting). Although possible, that would be a very clumsy thing to do, and really not worth the effort. See my other answer for a way to do that.


    There are two php.ini settings you might be interested in:

    auto_prepend_file and auto_append_file

    They can be changed via .htaccess (see the other answer).

    NOTES:

    • These will be included before or after the whole PHP script; but not in specific sections of the output.

    • They will only affect files handled that go through PHP, which means HTML files are not included, unless your server is set up to pass HTML files through PHP. This can be done by adding the following line to your .htaccess:

      AddType application/x-httpd-php .html .htm
      
    • Auto prepending a file that generates output is a dangerous thing to do, because it will affect (break) scripts that set headers or use sessions.

提交回复
热议问题