Creating a simple hitcounter for PHP web pages. (saves to files)



To make this work on a single page you will need to create/modify 4
files.
So here goes...

Create a file called counter.php and put following code in it:
<?php
//Counter
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$hit_count = $hits[0];
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
//echo $hits[0];

//Details to add to list
$count_my_page = ("hitcounter.csv");
$fp = fopen($count_my_page , "a");
$ip=$_SERVER[REMOTE_ADDR];
$dnsname = gethostbyaddr($ip);
$referer=$_SERVER[HTTP_REFERER];
$page=$_SERVER[PHP_SELF];
$now = date( "Y/m/d H:i:s", time() );
fputs($fp , "$now,$hit_count,$page,$ip,$dnsname,$referer\r\n");
fclose($fp);
?>

Then create a file called hitcounter.txt and put value 0 in it.

Then create a file called hitcounter.csv and put following text in it:
TimeStamp,Count,Page,IP-Adress,DNS,Referer

Remember to give write permitions to the hitcounter files for your
local internet account and you done.

Now on every PHP web page you have add the following code between the
<header></header> or <body></body> tags:
<?php include ("counter.php"); ?>

If you link .csv file to excel when you click on the csv file you will
be promted to open it with excel.
If you do you get a nice grid layout of the data.
.



Relevant Pages

  • Creating a simple hitcounter for PHP web pages. (saves to files)
    ... To make this work on a single page you will need to create/modify 4 ... Now on every PHP web page you have add the following code between the ... If you link .csv file to excel when you click on the csv file you will ...
    (comp.lang.php)
  • Re: CSV import, excel corrupts data
    ... I guess if you want to use excel, you'll have to play by its rules. ... If opening .csv files directly doesn't work for you, ... Doing the macro trick corrupts the data as described when the file is a ... empty worksheet, use the data import wizard to select the csv file, ...
    (microsoft.public.excel)
  • Re: CSV import, excel corrupts data
    ... It _does_ bring up the data import wizard. ... There really seems to be no way to accomplish this in excel. ... Doing the macro trick corrupts the data as described when the file is a ... empty worksheet, use the data import wizard to select the csv file, ...
    (microsoft.public.excel)
  • Re: Basic Program to Import a CSV file
    ... Given that the OP asked about importing a CSV file into UV, ... some Excel to MV tool to import a CSV file into UV? ... Hey, why stop at replacing the database, replace the spreadsheet tools ... The directory file may well be UV ...
    (comp.databases.pick)
  • Re: On File open - how to stop conversion of postcodes to numbers
    ... definite failing of Excel to anticipate correctly the programmers wishes. ... a space before every entry in the postcode field before the first number just ... I could write an automated macro to run the file wizard but I would forever ... When I open CSV file using Notepad the field contains "00037" so it is all ...
    (microsoft.public.excel.worksheet.functions)