Displaying Counter

Everything related to CCount PHP click counter
Post Reply
saud
Posts: 1
Joined: Sun Mar 06, 2005 11:14 pm

Displaying Counter

Post by saud »

Hello junkyard

I have changed the code a little. Now you can display the counter directly without the help of Javascript. I think that you should include this modifed code with your setup. This is the easiest way to display the codes.

You have to include this tag in your php pages <?php include("http://www.domain.com/display.php?id=1"); ?>

and the display.php code is

Code: Select all

<?php
# PHP click counter (CCount) - display number of clicks on a link
# Version: 1.1
# File name: display.php
# Written 22nd January 2005 by Klemen Stirn (info@phpjunkyardNOSPAM.com)
# http://www.PHPJunkYard.com

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

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

require_once "settings.php";

// First check if the ID is set and if it is valid (contains nothing but numbers)
$id=$_GET['id'];
if(empty($id) || preg_match("/\D/",$id)) {die("Invalid ID, numbers (0-9) only!");}

// Different systems use different line endings
if($settings['system'] == 2) {$newline="\r\n";}
elseif($settings['system'] == 3) {$newline="\r";}
else {$newline="\n";}

// Get lines from file
$lines=file($settings['logfile']);

// Let's found the line that starts with our ID number
$found=0;
$i=0;
foreach ($lines as $thisline) {
    if (preg_match("/^($id\%\%)/",$thisline)) {
    	$thisline=chop($thisline);
    	// We found the line, now we get URL and count from the line
        list($id,$added,$url,$count,$name)=explode("%%",$thisline);
        // Increase count by 1 and update this line
        $lines[$i]=$id."%%".$added."%%".$url."%%".$count."%%".$name.$newline;
        $found=1;
        echo "$count";
        break;
    }
    // This line didn't start with ID, lets go to the next one
    $i++;
}

You can see the demo here http://www.ffasite.webhostingcafe.com/s ... hemes1.php

I have not used the Javascript to display the code
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Hi,

Nice for inclusion in PHP scripts, but takes more processing (= system resources) than the javascript solution if you display count for more than one link.

BTW: Please edit your post so it reflects the mod submission rules found at
http://phpjunkyard.com/developers/viewtopic.php?t=2

Thanks and regards
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
TheDebut
Posts: 1
Joined: Sun Aug 05, 2007 7:41 pm

Post by TheDebut »

Hello!

I would like to use this mod, because my webhosting company doesn't allow to run javascripts, in fact of that I can't display the actual download counts on my page. With this modified version I believe I could use only php codes. Unfortunetly im not a pro in php so I couldnt figure what to write to my html page to display the counts.

I edited display.php + added <?php include("http://www.domain.com/display.php?id=1"); ?> line instead of javascript, but i don't know how to display the counts (i mean i need a code instead of <script language="Javascript">ccount_display('1')</script> )
Can u tell me what that code is?

Thx !
mlacy03
Posts: 1
Joined: Tue Nov 27, 2007 10:33 pm

Post by mlacy03 »

I actually would encourage the use of the PHP example, since some users may have their javascript disabled, or forcibly disabled from their corporate LANs. When looking through the code, this was the one thing that stood out as being strange to an otherwise great piece of software.

Actually, you could make the code even easier by writing the same funtion in display.php as a PHP function, and just do

Code: Select all

<?php ccount_display(id); ?>
Again, this is a great piece of work, but with my PHP experience, I try to stay away from such things as Javascript, since it requires more client-side configuration to pull off. Granted, I use it in a pinch, but for things that require items to be displayed consistently between systems, I would choose PHP over JS any day.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Well, look at it this way - most CCount users already have their website finished and from what I've seen in these years most users use plain HTML pages. It's easier to paste some JS instead of changing your pages to PHP just because you want the count displayed (and keep in mind for many CCount is their first PHP experience).

Besides, a wast majority of people have JS enabled. The user-agents that don't are mostly bots. But if you know PHP it shouldn't be too hard to write a PHP display_count function.
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
MadnessRed
Posts: 2
Joined: Wed Apr 16, 2008 4:34 pm

hmm

Post by MadnessRed »

I think that this could be really useful. I prefer php to js
anyway 2 things.

Code: Select all

<?php
# PHP click counter (CCount) - display number of clicks on a link
# Version: 1.1
# File name: display.php


#dot dot dot#
 

$lines[$i]=$id."%%".$added."%%".$url."%%".$count."%%".$name.$newline;
        $found=1;
        echo "$count";
        break;
    }
    // This line didn't start with ID, lets go to the next one
    $i++;
} 
shouldn't the php tag be closed?

Code: Select all

?>
and the other thing is,

it doesn't work for me?
just says

Invalid attempt!

any ideas.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Yes, PHP scripts should be closed with ?> but I think it works also if the last ?> is missing.

As for the invalid attempt, add this code above the first "require" call:

Code: Select all

define('IN_SCRIPT',1);
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
MadnessRed
Posts: 2
Joined: Wed Apr 16, 2008 4:34 pm

ok thanks that fixed it

Post by MadnessRed »

ok, thankyou, that fixed it.

any for the benefit of anyone else with that problem the code
<?php
# PHP click counter (CCount) - display number of clicks on a link
# Version: 1.1
# File name: display.php
# Written 22nd January 2005 by Klemen Stirn (info@phpjunkyardNOSPAM.com)
# http://www.PHPJunkYard.com

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

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

define('IN_SCRIPT',1);

require_once "settings.php";

// First check if the ID is set and if it is valid (contains nothing but numbers)
$id=$_GET['id'];
if(empty($id) || preg_match("/\D/",$id)) {die("Invalid ID, numbers (0-9) only!");}

// Different systems use different line endings
if($settings['system'] == 2) {$newline="\r\n";}
elseif($settings['system'] == 3) {$newline="\r";}
else {$newline="\n";}

// Get lines from file
$lines=file($settings['logfile']);

// Let's found the line that starts with our ID number
$found=0;
$i=0;
foreach ($lines as $thisline) {
if (preg_match("/^($id\%\%)/",$thisline)) {
$thisline=chop($thisline);
// We found the line, now we get URL and count from the line
list($id,$added,$url,$count,$name)=explode("%%",$thisline);
// Increase count by 1 and update this line
$lines[$i]=$id."%%".$added."%%".$url."%%".$count."%%".$name.$newline;
$found=1;
echo "$count";
break;
}
// This line didn't start with ID, lets go to the next one
$i++;
}
?>
and to show it
(the red bits are new)

also the
<script language="Javascript" src="http://madnessred.co.cc/go/display.php">
<!--
//-->
</script>
I dont think is needed.
Post Reply