How to create a counter on the web page in HTML?

Discussion in 'HTML & Website Design' started by alisha0512, Jul 29, 2008.

  1. #1
    Please tell me the code to create a counter on the web page with the help of html.
     
    alisha0512, Jul 29, 2008 IP
  2. ajohn03d

    ajohn03d Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First off all you need your page to be a .php for example index.php then you would need to open up dreamweaver or what ever you use and create a .php then put this in it:

    <?php
    $visit = fopen("log.txt","r");

    $counter = fgets($visit,1000);
    fclose($visit);

    $counter=$counter + 1 ;
    echo "$counter" ;

    $visit = fopen("log.txt","w");

    fwrite($visit, $counter);

    fclose($visit);
    ?>

    Then save it as hits.php, Now open up the page you would like to count the hits on and place this code in <? include ("hits.php"); ?>

    Now have you noticed in that php above you can see a file name called log.txt, This is the file that your hits store in. Now you need to create a file on your webserver and name it list.txt. Give it permissions to read and write.

    save and upload, Enjoy!

    You cannot create a counter using html, Well of my knowledge

    Hope that helps you alot!
     
    ajohn03d, Jul 30, 2008 IP
  3. nirmala.prc

    nirmala.prc Active Member

    Messages:
    329
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Nice code from ajohn03d.

    And of course, you cannot create counter with html itself. Because, you need to store a value of counter some common place . For that you need a server place. Hence server place means , automatically you need any server script.

    The above code is good, may need some tweak when you run it on server, like 777 chmod for the file etc.

    Anyways, try your best from some search in google.

    Best Regards,

    Nirmal
     
    nirmala.prc, Jul 30, 2008 IP
  4. alisha0512

    alisha0512 Banned

    Messages:
    345
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4


    which server will i need?
     
    alisha0512, Aug 11, 2008 IP
  5. xira

    xira Active Member

    Messages:
    315
    Likes Received:
    8
    Best Answers:
    4
    Trophy Points:
    68
    #5
    Outside of needing more complicated code than HTML, as a general rule of thumb counters are a bad idea. You will be showing people how "unpopular" your website is, until it is "popular". It's anti-marketing. Most hosting companies supply web statistics software as part of their hosting package. You can find out how many people visited your site, and which pages using that. Ask your host about which web statistic software you have access too. Good luck
     
    xira, Aug 12, 2008 IP
  6. bobbydeo

    bobbydeo Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The code given should work on any server where php is enabled.

    But as xira said it is not advisable.

    You can also install a counter using some html code if your host gives this facility. Like in cpanel theres an inbuilt script where you just need to add a line of html code and your are done.
     
    bobbydeo, Aug 13, 2008 IP
  7. laura_d

    laura_d Peon

    Messages:
    232
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hey alisha0512,

    You can get a free html counter at statcounter, it
    in my opinion is the best and of course its free.

    It has various trackers, you can also see how long
    a visitor stays on any given page, what keywords
    they used to get to your website.

    Check it out.

    Yours,


    Laura_D
     
    laura_d, Aug 13, 2008 IP
  8. alisha0512

    alisha0512 Banned

    Messages:
    345
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Okkkkkkk,
    Thanks
     
    alisha0512, Aug 13, 2008 IP