Background: I\'ve got some code that checks to see if a user has a valid session before processing the php page that I would like to set as the auto_prepend_file. However,
There is a great tutorial called: Automatically Include Files with PHP & Apache that explain how to do that with the apache directive and PHP code to append at the end. First, define a file to catch the page before it's outputted and append whatever you want:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
GA;
$replace = array('',''); $page = str_replace($replace, "{$script}\r", $page); // $replace2 = array('',''); // $page = str_replace($replace2, " - My Awesome Site", $page); return $page; } ob_start("appendToFile"); ?>
Then add the Apache directive to your virtual host. You need to prepend the PHP file in order to use the ob_start() method :
AddType application/x-httpd-php .html .htm
php_value auto_prepend_file /absolute/path/to/apache-prepend.php