Alex Rivera | Logout

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

Asked 2010-09-25T01:31:21.900
10

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:

A) How do I add this right BEFORE the </head> tag
B) How do I add right right AFTER the <body> tag

I'd like to know both methods for flexibility

I think .HTACCESS could accomplish this easily, and if you know how, or if you know of any easier method then please do share.

P.S. I do not want to manually go in and enter a code on every file, that is why I am asking this question (for time saving)

Edit
Report

1 Answer

3

You can append or prepend files by setting a PHP ini value in .htaccess

php_value auto_prepend_file "full_path_to_the_include_directory/prepend.php" 
php_value auto_append_file "full_path_to_the_file_containing_your_analytics_code" 

(It'd be better to set them manually in php.ini)

http://php.net/manual/en/ini.core.php

answered 2010-09-25T01:33:36.803

Your Answer