Mobile app version of vmapp.org
Login or Join
Kevin317

: Is it possible to count the number of hits or loads of a webpage without anything fancy? I know very little, but I do know that I have some server space given by my University with a file

@Kevin317

Posted in: #Apache #Configuration #Traffic

I know very little, but I do know that I have some server space given by my University with a file called public_html which anyone can load html and other files from. So is there a simple way to add some file and edit it with vim or give it a special name and have it collect the number of times a web browser loads a particular html file in public_html? I figure since there are a lot of settings files such as .vimrc or .forward which simply require a name and maybe input. I am hoping there is something like this which will record each time html is accessed in my public_html folder.

Is there such a thing, or am I too hopeful? It seems like a practical feature but like I said I really do not know much about this stuff. Thanks.

I actually do not know if this server space is apache or not, but my engineer account definitely says apache 2.2.15 (Red Hat) at the bottom of any 404 error, so I am really just guessing.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

2 Comments

Sorted by latest first Latest Oldest Best

 

@Dunderdale272

Supposing your server space supports PHP, you can:

1) Place into the public_html folder a file called idious-counter.php with this code into it:

<?php

define("COUNTER_START_VALUE", 0);
define("COUNTER_LOG", "idious-counter.log"); //name of file you want to use to save the counter value

/*************************************************************************************************/
function IncrementCounter()
{
$create_file = !file_exists(COUNTER_LOG);

if( !($fh = fopen(COUNTER_LOG, $create_file ? "x+b" : "r+b")) )
return "Error";
//do an flock here, maybe, I don't know :-)

//Reading current value of counter:
if($create_file)
$count = COUNTER_START_VALUE;
else
{
$count = (int)fread($fh, 9); //reads 9 digits (supposing max 1 billion count)
rewind($fh);
}

//Writing new counter value:
if(!fwrite($fh, ++$count))
return "Error";
if(!fclose($fh);)
return "Error";

return str_pad($count, 9, '0', STR_PAD_LEFT);
}

?>


2) In your index.html file add somewhere this line:

<h3>You are visitor number: <?php include("idious-counter.php"); echo IncrementCounter(); ?></h3>

10% popularity Vote Up Vote Down


 

@Sue5673885

Yes, it is definitely possible to count the number of hits by just using a few lines of HTML Code. But then you might also need a bit of PHP code in the root directory of the site.

But if you don't want to go with all these hassles then just search for free website hit counter in any search engine and you will be served with a ready made code of html which you can place at the bottom of index.html page and the rest is taken care by itself. One such quick search bought me to this website: www.simplehitcounter.com/
And if you want to get into the details of exactly what your visitors are doing and their geo-location and other details then you might have to go for higher options like Google webmaster tools or Piwik.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme