Website Ideas blog dedicated to web-developers for design inspiration
May 22, 2012, 04:06:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome To Website Ideas blog dedicated to web-developers for design inspiration
 
 Website Ideas  Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Simple Hit counter  (Read 1532 times)
0 Members and 2 Guests are viewing this topic.
peter123
Newbie
*
Posts: 1


View Profile Email
« on: November 10, 2008, 12:31:53 PM »

A hit counter will let us know how many times a page is accessed. In case one visitors loads the page several times, the hit counter will increase several times (but this is likely to happen only a few times).

The code for the hit counter bellow will save the number of hits in a file named counter.txt (the name of this file may be changed). Each time the page is loaded, the file will be read, the number will be increased by one and the new number will be saved to the same file.

<?php

//The file where number of hits will be saved; name may be changed; p.e. "/counter_files/counter1.txt"
$counterfile = "counter.txt";

// Opening the file; number of hit is stored in variable $hits
$fp = fopen($counterfile,"r");
$hits = fgets($fp,100);
fclose($fp);

//increading number of hits
$hits++;
//http://www.infysolutions.com
//saving number of hits
$fp = fopen($counterfile,"w");
fputs($fp, $hits);
fclose($fp);

//printing  hits; you may remove next line (and keep the counter only for your records)
print $hits;

?>
To use this code, copy it to your page in the exact position where you want to show number of hits.

Outsourcing software development
Ricardo
Newbie
*
Posts: 7


View Profile
« Reply #1 on: October 22, 2009, 04:27:54 PM »

Cool - Thanks for posting the code. I have a question about hit counters.

It seems to me that I noticed them much more a few years ago than I do now. So do you think that's the trend, and if so could you hide the counter from being seen by your visitors?

Arguy
Newbie
*
Posts: 48


View Profile
« Reply #2 on: November 27, 2009, 01:31:03 PM »

That's fantastic. Thanks for sharing it. Currently I am using free ready made hit/stat counter named Histats. It is a good stat counter which provide you data of many parameters.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.043 seconds with 19 queries.

Google visited last this page May 08, 2012, 07:27:52 PM