Visualize visits on a graph
Posted: Sun Mar 18, 2012 1:40 am
Hi,
I downloaded the visit counter for my personal site and added some functionalities that you might be interested in including in the original script -or not-. I added a history so the counts at the end of a day will be stored in a file together with the date so you can, for example, plot the number of visits as a function of time.
The code I wrote to create the history is
Also, I created a php script that invokes gnuplot to create a graph that is generated in real time with the history data - of course gnuplot needs to be installed in the server.
You can check the "visitors" link at the bottom of my page http://miguelcaro.com.es/ if you are interested.
Just thought some people might be interested in this kind of functionality (I am) without needing to rely on some external provider as Google or so.
Miguel
I downloaded the visit counter for my personal site and added some functionalities that you might be interested in including in the original script -or not-. I added a history so the counts at the end of a day will be stored in a file together with the date so you can, for example, plot the number of visits as a function of time.
The code I wrote to create the history is
Code: Select all
/* Print to visits history */
$datetoday = date("Y m d");
$hislogfile = "logs/" . "history_" . $page . ".txt";
$vh = @fopen($hislogfile,"a+");
$lastdateinfile = exec("tail -1 $hislogfile | cut -c1-10");
$lastdateinfile2 = trim ($lastdateinfile);
if ( $datetoday == $lastdateinfile2 ) {
$numberoflines = exec("cat $hislogfile | wc -l");
exec("sed '$numberoflines d' < $hislogfile > logs/temp; cp logs/temp $hislogfile");
fputs($vh, $datetoday." ".$count."\n");
fclose($vh);
}
else {
fputs($vh, $datetoday." ".$count."\n");
fclose($vh);
You can check the "visitors" link at the bottom of my page http://miguelcaro.com.es/ if you are interested.
Just thought some people might be interested in this kind of functionality (I am) without needing to rely on some external provider as Google or so.
Miguel