View Full Version : web counter
hilmaniac
06-09-2008, 01:13 AM
hi...
I need some help from you...I wanna make web counter on my website,can you help me....coz I have already done with my counter but it doesn't works good...help me plizz
Heres a way to do it in PHP, on every page you want to put this code:
<?php
include('counter.php');
?>
And then on counter.php:
<?php
function counter($file){
$fdata = fopen($file, 'w');
$data = file_get_contents($file);
$newData = $data+1;
fwrite($fdata, $newData);
fclose($fdata);
}
counter('counter.txt');
?>
You'll find a file that's automatically created called "counter.txt", thats where the number of hits you got are. Also it can be the same person refreshing there page rapidly. So I can create it so it only counts for one person once a day if you want. But tell me if you do.
You can also take a look at this witch isn't what you wanted. But:
http://www.dynamicdrive.com/forums/showpost.php?p=145816&postcount=7
allahverdi
06-09-2008, 06:15 PM
You can do it with db too.
Like when press to link, call function. Then get old count and make $newcount = $oldcount+1;
Only you will need is to update the count:
$result = mysql_query("UPDATE counter SET count = '$newcount' WHERE id = '$id'");
if you have question can ask ^^
ramaraju
05-28-2013, 04:20 AM
hello... my question is ...
how to know how many visitors already visited in my site....
tell me, plz help me
ramaraju,
Please start a new thread to ask your question.
The last reply in this thread was almost five years ago - there is almost never an acceptable reason to post in such an old conversation.
Read the Forum Rules (http://www.dynamicdrive.com/forums/rules.htm) before starting your thread.
This thread (http://www.dynamicdrive.com/forums/showthread.php?24866-Forum-Rules-Read-First) is also a good place to learn about the rules here on DynamicDrive.
If you are looking for a complete script that you can use, post in the Looking for such a script or service (http://www.dynamicdrive.com/forums/forumdisplay.php?23) forum (or, read Nile's reply (http://www.dynamicdrive.com/forums/showthread.php?33272-web-counter&p=146859#post146859), above).
If you are trying to write one yourself, post in the PHP (http://www.dynamicdrive.com/forums/forumdisplay.php?11) forum.
how to know how many visitors already visited in my site....
Note that it is not possible to determine how many visitors you have already had: any script will be able to record only subsequent visits.
Also,
Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?
Please be sure that you have included all relevant code and/or a link to the page in question.
You might also consider making a reduced test case (http://css-tricks.com/reduced-test-cases/) using an online tool like jsfiddle (http://jsfiddle.net)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.