Jump to content

Recommended Posts

Posted

Hi,

 

On my home page I would like to display a list of my most popular pages based on user visits. The majority of my pages are html. Almost all of the of php counters I've seen require me to add php but, I'd prefer not to convert my static pages to php.

 

Does anyone have recommendations on how to count hits to html pages, store in flat file or mysql db and then retrieve the "top 5" or "top 10" ? Can I pull this from awstats somehow?

Thanks

mk

Posted

Welcome to the forum mk :)

 

To use php scripts in your html files add

 

AddHandler application/x-httpd-php .htm .html

 

to your .htaccess file

then your server will look at your html and htm files for php code

and run the php code it finds.

 

Now you can look at hotscripts.com for a script to do what you want.

Posted

Hi,

 

Since I got such a fast/good response I my first post I was hoping someone could help me out. I added the AddHandler line to my .htaaccess but instead of going to HotScripts or PHP Freaks to find a counter script, I decided to create my own.

 

Below is the script/DB queries I'm trying to test(I will expand it later), I also added <?php @include_once("counter.php");?> to an html file to test.

 

<?php>

require_once('mysql_connect.php');

 

$URL=$_SERVER['HTTP_REFERER'];

$q = "SELECT * FROM counter where url='$URL'";

$r = mysql_query($q);

$rw = mysql_fetch_array($r, MYSQL_ASSOC);

$count = $rw['count'];

$dt = date("Y-m-d");

 

if($rw['url'] && $rw['date'] == $dt)

$qu = mysql_query("UPDATE counter SET count = '$count + 1' WHERE url='$URL'");

else

$qu = mysql_query("INSERT INTO counter(url, count, date) VALUES ('$URL', '1', '$dt'"); // first entry

?>

 

My problem occurs with the $URL variable. It's not being passed the url of the html page that is calling the script. I tried setting $_SERVER['PHP_SELF'] but that just sets $URL="counter.php" Does anyone know what I'm doing wrong? I've looked on php.net for other variables but don't know which would cover what I'm trying to do.

 

Thanks!

Mike

Posted

Please disregard....

 

the query:

 

$qu = mysql_query("INSERT INTO counter(url, count, date) VALUES ('$URL', '1', '$dt'");

 

was missing a close paren at the end, should have been.

 

$qu = mysql_query("INSERT INTO counter(url, count, date) VALUES ('$URL', '1', '$dt')");

 

Thanks!

  • 2 weeks later...
Posted
Hi,

 

On my home page I would like to display a list of my most popular pages based on user visits. The majority of my pages are html. Almost all of the of php counters I've seen require me to add php but, I'd prefer not to convert my static pages to php.

 

Does anyone have recommendations on how to count hits to html pages, store in flat file or mysql db and then retrieve the "top 5" or "top 10" ? Can I pull this from awstats somehow?

Thanks

mk

 

 

Have you looked into this Daily Counter 1.1 Then there is a tutorial here Daily Counter 1.1 modifications for including it into html pages

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...