1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Simple Hit counter

Discussion in 'Web Design & Development' started by david_12, Oct 6, 2008.

Thread Status:
Not open for further replies.
  1. david_12

    david_12 Thread Starter

    Oct 6, 2008
    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.


    //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);

    //increading number of hits

    //saving number of hits
    $fp = fopen($counterfile,"w");
    fputs($fp, $hits);

    //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
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 733,556 other people just like you!

Similar Threads - Simple counter
  1. babyb01
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/756555

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice