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

前端 未结 5 910
一生所求
一生所求 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 05:58

    Here's what you could do accomplish what you actually want.

    • Create two files, called prepend.php and append.php.
    • Use the method previously described to set them as auto_prepend_file and auto_append_file.

    prepend.php

     tag
        return str_replace('', $fileContents . '', $buffer);
    
        // insert $fileContents right AFTER  tag
        // return str_replace('', . '' . $fileContents , $buffer);
    
    }
    
    ob_start("callback");
    
    ?>
    

    append.php

    
    

    This relies on output buffering and is relatively expensive. You might also run into problems if your scripts also use output buffering.

    So my best advice is to design your scripts in a way that the a layout is used for every page and you can easily change what's included in your pages by just changing the layout.

提交回复
热议问题