ahs10 Posted September 20, 2007 Share Posted September 20, 2007 i have a sub-directory within my site that has many HTML files. these files are accessed via many different links within my site. i would like to get usage reporting on the directory, but not quite sure what the best way to do that is. all i need is a count of how many times any file in this directory is viewed, i don't need a separate count for each individual file. my only idea so far is to have each HTML run a php script that updates a db count. can you have HTML run a PHP script when it loads? i know i could change each link to pass an id through the URL, to a script that updates a db count, then refreshes to a URL according to that id. however, there are a lot of different links to these files, in many different types of places (flash being one for example). i'd like to stay away from link editing, if possible. can anyone help me out please? thanks for your time. take it easy. Quote Link to comment https://forums.phpfreaks.com/topic/70019-solved-usage-reporting-on-a-directory/ Share on other sites More sharing options...
Orio Posted September 20, 2007 Share Posted September 20, 2007 HTML files can't call php files. But, you can add/edit the directory's .htaccess and add this line: AddType application/x-httpd-php .htm .html This way html files will be treated as php files. (See info here). Now, at every file you can add on the top this line: <?php include("page_counter.php"); ?> rest of html here page_counter.php will use $_SERVER['PHP_SELF'] to increase the count of the page in a database/flat-file. That's the simple solution I can think of. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70019-solved-usage-reporting-on-a-directory/#findComment-351669 Share on other sites More sharing options...
wildteen88 Posted September 20, 2007 Share Posted September 20, 2007 If you dont want to update all your .html files then you could use mod_rewrite for this. Using mod_rewrite you'll catch the requested html file and then pass this html file to a php script, the php file will include the requested HTML file, and update the file statics at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/70019-solved-usage-reporting-on-a-directory/#findComment-351687 Share on other sites More sharing options...
ahs10 Posted September 20, 2007 Author Share Posted September 20, 2007 thanks guys. i think i'll go with the .htaccess file, since the server could change in the future. thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/70019-solved-usage-reporting-on-a-directory/#findComment-351708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.