# Web Site Counter?

**URL:** <https://forum.kirupa.com/t/web-site-counter/111155>\
**Category:** Uncategorized\
**Created:** [May 24, 2004, 10:06am UTC](https://forum.kirupa.com/t/web-site-counter/111155 "2004-05-24T10:06:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![red\_A](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@red\_A](https://forum.kirupa.com/u/red_A)\
**Post date:** [May 24, 2004, 10:06am UTC](https://forum.kirupa.com/t/web-site-counter/111155/1 "2004-05-24T10:06:56Z")

</div>

Well i need to add website counter, and i was wondering if anyone would recommend any of the freeware counters avaliable out there or even a link to some tutorials regarding php counters???

all comments or suggestions are welcome 🙂

-AlBERT

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 26, 2004, 11:10am UTC](https://forum.kirupa.com/t/web-site-counter/111155/2 "2004-05-26T11:10:02Z")

</div>

PHP and MySQL

create table : counter ( id int(6), ip varchar(20), time varchar(40) )  
create table : total ( view int(6) )  
exp  
\<?php  
require (“db.php”); // copy from includes/db.php of phpbb forum  
function counter () {  
global $db; // I uses my\_sql class from phpbb  
$time\_refresh = 5\*60; // 5 mins  
$ip = $\_SERVER[“REMOTE\_ADDR”];//get ip browser  
$past = time()-$time\_refresh;  
$sql = “DELETE FROM counter WHERE time \< $past”;  
$db-\>sql\_query($sql);  
$sql = “SELECT time FROM counter WHERE ip=’$ip’”;  
$result = $db-\>sql\_query($sql);  
$exist = $db-\>sql\_numrows($result);  
if($exist == 0) {  
$sql = "UPDATE total SET view=view+1;  
$db-\>sql\_query($sql);  
}  
}  
$sql = “SELECT view FROM total”;  
$result = $db-\>sql\_query($sql);  
$row = $db-\>sql\_fetchrow($result);  
$visit = $row[view];  
echo “there are “.$visit.” visitors”;  
?\>

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 26, 2004, 4:11pm UTC](https://forum.kirupa.com/t/web-site-counter/111155/3 "2004-05-26T16:11:21Z")

</div>

um, [bravenet.com](http://bravenet.com) ??? hehe…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 26, 2004, 11:47pm UTC](https://forum.kirupa.com/t/web-site-counter/111155/4 "2004-05-26T23:47:23Z")

</div>

make a file called counter.php and put:

\<?php  
$count\_my\_page = (“hitcounter.txt”);  
$hits = file($count\_my\_page);  
$hits[0] ++;  
$fp = fopen($count\_my\_page , “w”);  
fputs($fp , “$hits[0]”);  
fclose($fp);  
echo $hits[0];  
?\>

Next you must make a file to include that function by:  
\<?php  
include (“counter.php4”);  
?\>

then make a blank text file called hitcounter.txt and chmod the permissions to 777.

this is not a unique ip counter… it will add +1 everytime you refresh the page.

hope this helps.
