free counter using MySql ?

Howling Wolf

We did not deserve this !
I'm looking for a free text counter (not graphical) that could use an already existing and working MySql database...

Any idea is more than welcome :)

I'd like to be displayed on my page a simple text number that increments with every unique visitor like this [ 286 ] for example.
Where and how should I insert this counter into my page(s) ?

Thank you in advance for your help !
You can just use PHP and a single text file. No need of a MySQL database.

$counter = "counter.txt"; 

function displayCounter($counter) { 
     $fp = fopen($counter,rw); 
     $num = fgets($fp,9999); 
     $fp = fopen($counter,w); 
     $num += 1; 
     print "$num"; 
     fputs($fp, $num); 


Howling Wolf

We did not deserve this !
Thank you both !
NetRyder, could you be a little more precise ?
What variable should I set/change ? Where should I insert the code, in my html page ? Should I change from .html to .php ? Will it count unique visitors and not all hits ?
Again, I'd like to use the table 'count' that's already working on my MySql database...
As you can see, I have no idea of what's to be done, thank you for your help !

P.s.: I have a counter at the moment, but I don't like it much (pretty ugly)
You're welcome ;)

This is basically a very simple counter script that displays the total number of hits (not unique visitors) as plain text.
You don't need to change any part of the code. Just copy and paste it exactly where you want the number to be displayed on your page.
Yes, you will need to rename your file to .php
You will also need to create a single blank text file called counter.txt in the same directory as your .php page.

That's all there is to it :)

Howling Wolf

We did not deserve this !
is it you script ?
If so, what could be added to it so that it only counts uniques and doesn't count me ?
That would be ideal for me !

Thank you ! :)


OSNN Veteran Addict
I use this

// Unique hit counter
$browser = $_SERVER['HTTP_USER_AGENT'];

// mysql get array
$mysql = mysql_pconnect("mysql_host","mysql_username","mysql_password");
$cnt_qry = mysql_query("SELECT * FROM stats");
$count = mysql_num_rows($cnt_qry);
$query = mysql_query("SELECT * FROM stats WHERE ip='$ip'");
$rows = mysql_num_rows($query);
if($rows < 1)
    $add_hit = mysql_query("INSERT INTO stats (ip,browser) VALUES ('$ip','$browser')");
echo "$count Unique";
It counts only Unique hits

MySQL structure is
CREATE TABLE `stats` (
`ip` VARCHAR( 24 ) NOT NULL ,
`browser` VARCHAR( 32 ) NOT NULL ,
PRIMARY KEY ( `id` )

The PHP Query to create if you cant use phpMyAdmin
$sql = 'CREATE TABLE `stats` ( `id` INT( 11 )'
$sql .= ' NOT NULL AUTO_INCREMENT, `ip` VARCHAR( 24 )'
$sql .= ' NOT NULL , `browser` VARCHAR( 32 ) NOT NULL , '
$sql .= 'PRIMARY KEY ( `id` ) ) TYPE = MYISAM ; ';
You could then put the stats php code into an includes directory in your site, and then use this to get it
<?php include "include/stats.php"; ?>
This assumes that the page getting the counter is in the parent folder to the include folder

| +images
| +include
`- stats.php
| index.php

You can see this code workin on my site It is the top one, the one below is supposed to count all hits but not ones which "come from my site" (like when you click one of the links on my site it shouldnt increment but it does)

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member