I have an analytics file (in php) that I would like to prepend to every page on my site so that I can monitor which pages are visited. How would I set up my .htaccess file to achieve this?
Currently I have:
<Files "*">
php_value auto_prepend_file /analytics.inc.php
</Files>
but it's not working as desired.
Also, if anyone can suggest a simpler way to collect site analytics, I'm all ears.
EDIT:
I would like the analytics file to be prepended to all files in all (sub)directories. Cu开发者_高级运维rrently only the root directory is having its files prepended.The path is incorrect for sure. it should be absolute path from the filesystem foot.
if anyone can suggest a simpler way to collect site analytics, I'm all ears.
Your web-server already logs every request.
Only thing you need is to parse these logs daily and collect any stats you need.
Note that web-server logs every request, so, it has it's advantages and disadvantages. It will log not only requests to PHP files as it in your case but to static files too, like images, pdfs and such. But it will also log every image on the page, so, one request to usual page will produce up to hundred records in the log file. So, you have to choose records to analyze.
Try removing the <Files "*">
and </Files>
and just do:
php_value auto_prepend_file /analytics.inc.php
Also make sure that the path to analytics.inc.php is correct, and its in the same dir as the .htaccess.
If it still doesn't work, seeing your apache error log file could help.
Try giving an absolute path to the analytics.inc.php file in the .htaccess. IIRC, the prepend directive looks for the file relative to the file you are including it into.
精彩评论