Author Topic: Counter that only counts UNIQUE visitors.  (Read 36964 times)

Offline wing

  • Jr. Member
  • **
  • Posts: 343
    • CarTalkCanada
Counter that only counts UNIQUE visitors.
« on: August 25, 2005, 11:25:35 AM »

I found a simply way to create a counter that ONLY counts unique visitors rather than counting every time index.php is hit.  What this counter does is counts only the session once.  If the user closes their browser and comes back it will count it again, but at least you won't get every click counted.

I have put the counter on all of my website and in the index.template.php file in my Themes directory ensures that I count all the visitors no matter which page they hit first but only count them once!

Put the following in your index.template.php file:
Code: [Select]
// My Counter
   include ("/PATH-TO/simplecounter.php");
 // call the counter option "1" is to not display the counter on the site itself.  0 displays it, if you want  to display the counts you'll have to be tackfull on where you put the counter.

Here's the code for simplecounter.php, I didn't bother using the db_query commands, I wrote it so it doesn't spit out errors if there is a problem with the database, because it's not critical:
Code: [Select]
include &

function showimage($count) {
$marker 0;
    while (
$marker strlen($count)) {
$digit substr($count$marker1);
$theme_dir "/counter/theme";
$theme 4;
$width 10;
$height 12;
         echo &
#39;<img src="&#39; . $theme_dir . &#39;/&#39; . $theme . &#39;/&#39; . $digit . &#39;.jpg" width="&#39; . $width . &#39;" height="&#39; . $he
ight . &#39;" border="0">&#39;;
counter($display) {

if (!
mysql_query("UPDATE simplecount SET count=(count + 1) WHERE count_id=1");
$result mysql_query("SELECT count from simplecount where count_id=1");
$count $myresult[0];
    if (
strlen($count) < 6) {
$size strlen($count);
     for (
$i 1$i $size$i++)
$count $count;
  if (
$display == 0)

Here's the dbconnect.php code:
Code: [Select]


$db_database "localhost";
$dbname "DBNAME";
$passwd ="YOURPASSWORD";

// Connect to Database
$db_connection mysql_connect($db_database$db_user$passwd);

Now create a table with phpmyadmin called 'simplecount'
Add count as varchar 255
and count_id as varchar 25

Add some values to them, say count = 0 and count_id = 1

count_id is your counter ID number, you can multiple for multiple instances in the same database.

You can change "showimage" to display some text instead.  I used a bunch of images called 1.jpg 2.jpg 3.jpg etc...

Hope that helps for anyone looking for a counter to count unique visitors.
« Last Edit: August 27, 2005, 11:07:21 AM by wing »

Offline mennou

  • Full Member
  • ***
  • Posts: 507
  • Gender: Male
    • Unitymix,network
Re: Counter that only counts UNIQUE visitors.
« Reply #1 on: August 25, 2005, 01:36:59 PM »
can u show me a sample at least?

Offline wing

  • Jr. Member
  • **
  • Posts: 343
    • CarTalkCanada
Re: Counter that only counts UNIQUE visitors.
« Reply #2 on: August 25, 2005, 01:45:28 PM »
Sample of what?  The counter?   ???

You can check it out at the bottom of my main page  My forums are currently disabled as they are not launched yet.  But if you click around on my site it's all php you will see the counter doesn't change.

Offline ThePriest

  • Jr. Member
  • **
  • Posts: 115
Re: Counter that only counts UNIQUE visitors.
« Reply #3 on: July 24, 2007, 07:48:56 AM »
Hi.  I think this is what I am looking for.  Has it been made into a mod package yet as I have no clue when it comes to creating databases etc.   What I want is a counter that will tell me how many unique individuals have accessed the site within the last day/month and not just page hits, perhaps by comparing their IP address and possible show the info on the stats page.

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Counter that only counts UNIQUE visitors.
« Reply #4 on: August 19, 2007, 06:00:27 AM »
The counter script in the site doesn't work for me. I clicked in various parts of the site and the counter kept increasing.
    Please do not PM me with support requests unless I invite you to.   ~

<H> I had zero posts when I started posting