hit count not moving

In case you have problems with some other PHPJunkyard script (not that there are THAT many).
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

hit count not moving

Post by edmund »

Script URL:
Version of script:1.0
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:

hi i have add a hit count to both my company web site home page and a subpage but why only the home page is working, the other is not moving at all. My company webpage is http://www.asterisk.com.sg
The other web page belong to the News section. Tks, pls help.
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

When I open the page with my browser it counts.
First the news page count was 2002.
When I clicked again it changed to 2003.

Greetings,
Henrie
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

php text hit-count not moving

Post by edmund »

thks Henrie for replying. I just went to my web site and it shows 2004. I thought it works now but then i close my browser and enter again, it still shows 2004. So i clear my cache and delete all my temp internet files and try again. It still shows 2004. I got no idea how come it works on your side. :(

Regards
Edmund

Henrie wrote:When I open the page with my browser it counts.
First the news page count was 2002.
When I clicked again it changed to 2003.

Greetings,
Henrie
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

What are your settings in graphcount.php file for
$count_unique
Enable counting unique hits only. For more information read Counting UNIQUE hits below.
$unique_hours
Number of hours a visit is counts as unique. For more information read Counting UNIQUE hits below.

Read the readme.htm for information about these settings.

Greetings,
Henrie
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Like Henrie said you seem to have counting unique clicks enabled, that's why it only counts each visit once (when I opened in IE it showed 2969 hits no matter how many times I reloaded the page, when I opened in another browser (FireFox) it showed 2970).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

hit count not moving

Post by edmund »

hi Klemen and Henrie,

sorry to reply only until now, i am offline for these few days. Fro the counting unique setting in graphcount.php file, i can't find any in my modified graphcount.php file. I have handed it over from my previous colleague and i am in charge of doing it now. Is it set as enabled if there is no setting in the php file? Also, i have found that whenever i clear my cache file, i am able to see the new count in my homepage. As for the second hit-count web page (news section), i can only see the new hit-count if i browse directly to this web page instead of jump from the homepage to the news section. Is this setting correct or wrong? pls advice, thanks.

Regards
Edmund
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Since you might have a modified version I would recommend that you try installing the original counter again and we can work from there:
http://www.phpjunkyard.com/php-graphica ... ounter.php
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

hit count not moving

Post by edmund »

hi, this is the modified code i have mentioned. pls take a look and see why this one work and not the original for my webpage. thanks for all the help.

Regards
Edmund
-----------------------------------------------------------------------------------

Code: Select all

<?php

# PHP graphical hit counter (PHPGcount)
# Version: 1.0
# File name: graphcount.php
# Written 10th May 2004 by Klemen Stirn (info@phpjunkyard.com)
# http://www.PHPJunkYard.com

##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 2004 PHPJunkYard All Rights Reserved.                            #
#                                                                            #
# The PHPGcount 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.                                                        #
##############################################################################

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

// URL of the folder where script is installed. INCLUDE a trailing "/" !!!
$base_url = "http://www.asterisk.com.sg/counter/";
// Default image style (font)
$default_style = "blgrv";
// Default counter image extension
$default_ext = "gif";
// Enable referer validation? 1 = YES, 0 = NO
$check_referer = 0;
// Domains that are allowed to access this script
$referers = array ("localhost","ebay.com");
// Count UNIQUE visitors ONLY? 1 = YES, 0 = NO
$count_unique = 0;

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

// Get page and log file names plus style and folder with images
$page = htmlentities($_GET['page']);
$logfile = "logs/" . $page . ".log";
if (empty($_GET['style'])) {$style = $default_style;}
else {$style = $_GET['style'];}
$style_folder = "styles/" . $style . "/";
if (empty($_GET['ext'])) {$ext = $default_ext;}
else {$ext = $_GET['ext'];}

// 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="1888";
}
// 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
if ($visited == "") {
  $count++;
  setcookie("visited", $count, time()+30);
  }
}

// Write the new $count in the log file
$file = fopen($logfile,"w+") or die("Can't open/write the log file!");
fputs($file, $count);
fclose($file);

// Print out Javascript code and exit
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();

// 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!");
}
?>
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

hit count not moving

Post by edmund »

hi Klemen,

actually i am wondering is the modified hit count php file your earlier version in 2004 or it is really been modified by others?

Regards
Edmund
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Try upgrading to the new one (version 1.1) and see if that helps. Should be easy to do, download the new version and read upgrade instructions in the readme.htm file.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

hit count not moving

Post by edmund »

hi Klemen,

I have upload the new version and changed the text file in the log folder from log file to txt file. I have also made the changes in the webpage to link to the new php script file. But when i do the testing, it still came out same error message "runtime error occur" and when i debug, it points to the script file. Sorry i have to change back to the old version now because the website is on Live. But frankly speaking between the old and the new php script, there seems to be quite alot of changes. Is it because there is some code in the old file that is needed to run smoothly but not exist in the new file? pls help me, i am very puzzled now. Thanks.

Regards
Edmund
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Changes have been made mostly for security and performance reasons. What kind of error do you get, should be a PHP error not Windows "Runtime error".
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

Post by edmund »

that's why i am puzzled. The error is "A Runtime Error has occurred. do you wish to Debug? Line: 1 Error: Syntax error"
i have compared both old and new script and checked that the info i need to input into the new script is the same as the old script. Same is for the web page itself as i only change the script filename. I've paste the new one with info added. pls take a look and see if is there anything i left out comapred with the old one i have paste earlier. Thanks for the help and reply.

Regards
Edmund

Code: Select all

<?php
#********************************************************************************
#  Title: PHP graphical hit counter (PHPGcount)
#  Version: 1.1 @ October 26, 2007
#  Author: Klemen Stirn
#  Website: http://www.phpjunkyard.com
#*******************************************************************************
#  COPYRIGHT NOTICE
#  Copyright 2004-2007 Klemen Stirn. All Rights Reserved.
#
#  This script may be used and modified free of charge by anyone
#  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS 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, in part or full, without prior
#  written consent is expressly forbidden.
#
#  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.
#******************************************************************************/

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

// URL of the folder where script is installed. INCLUDE a trailing "/" !!!
$base_url = "http://www.asterisk.com.sg/counter/";
// Default image style (font)
$default_style = "blgrv";
// Default counter image extension
$default_ext = "gif";
// Count UNIQUE visitors ONLY? 1 = YES, 0 = NO
$count_unique = 0;
// Number of hours a visitor is considered as "unique"
$unique_hours = 24;
// Minimum number of digits shown (zero-padding). Set to 0 to disable.
$min_digits = 0;

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

// Turn error notices off 
error_reporting(E_ALL ^ E_NOTICE);

// Get page and log file names 
$page       = input($_GET['page']) or die('ERROR: Missing page ID');
$logfile    = "logs/" . $page . ".txt";

// Get style and extension information 
$style      = input($_GET['style']) or $style = $default_style;
$style_folder  = "styles/" . $style . "/";
$ext        = input($_GET['ext']) or $ext = $default_ext;

// Does the log exist? 
if (file_exists($logfile)) {

    // Get current count 
    $count = trim(file_get_contents($logfile)) or $count = 0;

    if ($count_unique==0 || $_COOKIE['gcount_unique']!=$page) {
        // Increase the count by 1 
        $count = $count + 1;
        $fp = @fopen($logfile,'w+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
        flock($fp, LOCK_EX);
        fputs($fp, $count);
        flock($fp, LOCK_UN);
        fclose($fp);

        // Print the Cookie and P3P compact privacy policy 
        header('P3P: CP="NOI NID"');
        setcookie('gcount_unique', $page, time()+60*60*$unique_hours);
    }

    // Is zero-padding enabled? 
    if ($min_digits > 0) {
        $count = sprintf('%0'.$min_digits.'s',$count);
    }

    // Print out Javascript code and exit 
    $len = strlen($count);
    for ($i=0;$i<$len;$i++) {
        echo 'document.write(\'<img src="'.$base_url . $style_dir . substr($count,$i,1) . '.' . $ext .'" border="0">\');';
    }
    exit();

} else {
    die('ERROR: Invalid log file!');
}

// This functin handles input parameters making sure nothing dangerous is passed in 
function input($in) {
    $out = htmlentities(stripslashes($in));
    $out = str_replace(array('/','\\'), '', $out);
    return $out;
}
?>
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

It's the correct code and I just checked it, there are no syntax errors. Also the http://www.asterisk.com.sg/counter/grap ... ndex.shtml seems to be working fine?

I also checked the response headers and the script is returning the cookie for counting unique hits so the count will only move once in a 24 hour period for you:
http://web-sniffer.net/?url=http%3A%2F% ... =GET&uak=0

This is still the 1.0 version installed, right? When upgrading to 1.1 make sure you rename all the files inside "logs" folder from "*.log" to "*.txt" as explained in the readme.htm file (see under Upgrading from old versions)
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
edmund
Posts: 8
Joined: Wed Mar 19, 2008 9:01 am

Post by edmund »

hi Klemen,

Currently for both index.shtml and news.shtml are using the version 1.0. They are working fine. The only puzzling thing is why when i change to version 1.1 they will come out syntax error. (I have rename all the file inside "logs" folder from "*.log" to "*.txt") Anyway, if using version 1.0 can work , i will just stick to it.

As for the hit count, which hour should i input for the following code if i want the hit count to move for every access to the webpage, hour 0?

// Number of hours a visitor is considered as "unique"
$unique_hours = 0;

Thank for reply,
Regards,
Edmund
Post Reply