Page 1 of 1

Unique Hits?

Posted: Sun Apr 30, 2006 12:48 am
by mikeyb987
Script URL: chambanatalk.com/gcount
Version of script:
Version of PHP: smf 107
Hosting company: godaddy
Have you searched THIS FORUM for your problem:
(if not please do before posting)
If so, what terms did you try: unique hits, and lots of others

Write your message below:

Is there a way to make the gcount only count unique hits- not count every time someone goes back to the index? Thanks alot- Mike

Posted: Fri May 12, 2006 10:33 pm
by zr
I *think* this will work

At the very top of the graphcount.php, below the copyright notice, add

Code: Select all

if (!isset($_SESSION['visit'])) {
then at the bottom right before "?>" add

Code: Select all

$_SESSION['visit'] = TRUE;

} else {

$count = $count - 1;

for ($i=0;$i<strlen($count);$i++) {
    $digit=substr("$count",$i,1);
    // Build the image URL ...
    $src = $base_url . $style_folder . $digit . "." . $ext;
    echo "document.write('<img src=\"$src\" border=0>');\n";
}

exit();

}
Let me know if that doesn't work :!: :!: :!: :) :) :)

Posted: Thu Jul 13, 2006 5:17 am
by yyvonne
Doesn't work for me.
Can someone paste the whole script here? Thanks.

Posted: Thu Jul 13, 2006 9:51 am
by Klemen
Try adding

Code: Select all

session_start();
just above this code

Code: Select all

if (!isset($_SESSION['visit'])) { 

Posted: Mon Aug 07, 2006 3:52 am
by yyvonne
I tried, but still doesn't work.
Hope someone can help me.

Code: Select all

<?php

# PHP hit counter (PHPcount)
# Version: 1.0
# File name: counter.php
# Written 15th July 2004 by Klemen Stirn (********************)
# http://www.PHPJunkYard.com

##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 2004 PHPJunkYard All Rights Reserved.                            #
#                                                                            #
# The PHPcount may be used and modified free of charge by anyone so long as  #
# this copyright notice and the comments above remain intact. By using this  #
# code you agree to indemnify Klemen Stirn from any liability that might     #
# arise from it's use.                                                       #
#                                                                            #
# Selling the code for this program without prior written consent is         #
# expressly forbidden. In other words, please ask first before you try and   #
# make money off this program.                                               #
#                                                                            #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium. In all cases copyright and header must remain intact. #
# This Copyright is in full effect in any country that has International     #
# Trade Agreements with the United States of America or with                 #
# the European Union.                                                        #
##############################################################################
session_start(); 
if (!isset($_SESSION['visit'])) {  

// SETUP YOUR COUNTER
// Detailed information found in the readme file

// Enable referer validation? 1 = YES, 0 = NO
$check_referer = 0;
// Domains that are allowed to access this script
$referers = array ("localhost","www.mysite.com");

#############################
#     DO NOT EDIT BELOW     #
#############################

// Get page and log file names
$page = htmlentities($_GET['page']);
$logfile = "logs/" . $page . ".log";

// If $check_referer is set to 1 and if HTTP_REFERER is set to
// a value let's check refering site
if ($check_referer == 1 && !(empty($_SERVER['HTTP_REFERER'])))
{
check_referer($_SERVER['HTTP_REFERER']);
}

// If the log file doesn't exist we start count from 1 ...
if (! @$file = fopen($logfile,"r+"))
{
$count="1";
}
// If the log file exist lets read count from it
else {
$count = @fread($file, filesize($logfile)) or $count=0;
fclose($file);
// Raise the value of $count by 1
$count++;
}

// Write the new $count in the log file
$file = fopen($logfile,"w+") or die("Can't open/write the log file, please CHMOD logs folder to 777 (rwx-rwx-rwx)!");
fputs($file, $count);
fclose($file);

// Print out Javascript code and exit
echo "document.write('$count');";
exit();

// function that will check refering URL
function check_referer($thisurl) {
	global $referers;
		for ($i=0;$i<count($referers);$i++)
        	{
				if (preg_match("/$referers[$i]/i",$thisurl)) {return true;}
			}
	die("Invalid referer!");
}

$_SESSION['visit'] = TRUE; 

} else { 

$count = $count - 1; 
echo "document.write('$count');";

exit(); 

} 
?>

Posted: Sat Jul 07, 2007 2:18 pm
by jayceegee
Hello Klemen,

Having tried the graphical hit counter, I find it excellent, but the code given by ‘zr’ to make it unique does not work, even with the mod you added later.

Is there any possibility, when time permits, that you could look at the code to enable the counter to only count unique hits, This would make it a first rate choice against the yucky “free” counters that come with (sometimes) unpleasant commercial links.

Regards, Jim.

Posted: Sun Jul 08, 2007 10:41 am
by Klemen
I might do that, but really don't know when. I'm currently writing my diploma and have little time to even check the forum, leave alone editing the scripts.

Posted: Sun Jul 08, 2007 12:45 pm
by jayceegee
Thank you Klemen, and good fortune with your studies.