Simple Hit counter

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

david_12

Thread Starter
Joined
Oct 6, 2008
Messages
0
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++;

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

http://www.infysolutions.com

Outsourcing software development
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top