Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/70019-solved-usage-reporting-on-a-directory/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.