Previous Thread
Next Thread
Print Thread
Hop To
Joined: Jun 2006
Posts: 2
S
stranger
stranger
S Offline
Joined: Jun 2006
Posts: 2
I have a hit counter that's working just fine in my overall footer. Copying and pasting into a custom island I cannot get to work.

Can anyone help? Here's the code:

PHP Code

<?php
#####################################################################
# PHP Web Counter, version 1.0									  #
#																   #
# A simple and light web hits counter							   #
#																   #
# This is a Free Software under Gnu/GPL license					 #
#																   #
# C 2006-2007 - Andre Bertelli Araujo <[email protected]>	#
#			   Joao Eriberto Mota Filho <[email protected]> #
#			   Marcos Patricio do Santos <[email protected]>	  #
#																   #
# URL: http://phpwebcounter.sourceforge.net						 #
#####################################################################


##############################
##############################
### Part 1 - Configuration ###
##############################
##############################

require("/home/sparky3/etc/phpwebcounter/phpwebcounter.config.php");

##########################
##########################
### Part 2 - The code! ###
##########################
##########################

function hits_webcounter($webcounter_id=0, $hits_file=null, $vis=null, $path_images=null, $counter_pad, $step) 
{
	if (is_null($hits_file))
		$hits_file = $path_hits_file;
	if (is_null($vis))
		$vis = $visible;

	$counter = read_webcounter($webcounter_id, $hits_file);
	increment_webcounter($webcounter_id, $counter, $step, $hits_file);
	
	if (!$vis) return;
	if (is_null($path_images)) {
		echo $counter;
	} else {
		show_webcounter($counter, $path_images, $counter_pad);
	}
}

function show_webcounter($counter, $path_images, $counter_pad=6)
{
	echo "<SPAN>";
		$counter = str_pad($counter, $counter_pad, '305611', STR_PAD_LEFT);
		for ($i=0; $i< strlen($counter) ; $i++) {
			$digit=$counter[$i];
			echo "<IMG src='$path_images/$digit.png' alt='$digit' />";
		}
	echo "</SPAN>";
}

function read_webcounter($webcounter_id, $hits_file=null)
{
	if (is_null($hits_file))
		$hits_file = $path_hits_file;

	$file="$hits_file/hits_webcounter.$webcounter_id";
	$fp = fopen($file, 'a+');
	$counter= fread($fp,1024);
	fclose($fp);
	return $counter;
}

function increment_webcounter($webcounter_id, $counter, $step=1, $hits_file=null)
{
	if (is_null($hits_file))
		$hits_file = $path_hits_file;

	$file="$hits_file/hits_webcounter.$webcounter_id";
	$fp = fopen($file, 'w');
	fwrite($fp,$counter+$step);
	fclose($fp);
}

########################
########################
### Part 3 - Running ###
########################
########################

hits_webcounter($webcounter_id,$path_hits_file,$visible,$path_images,$counter_pad, $step);

if ($banner == '1') { 
	echo '<br><a href="http://phpwebcounter.sourceforge.net"><font size=1px>PHP Web Counter</a></font size><br>';
	}
?>


Last edited by Gizmo; 08/19/2010 2:03 PM. Reason: [code] tags
Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
Off the top of my head, I think what you should do is put all of the functions into a single file. Then in the custom island you'd do something like:

PHP Code

require("/home/sparky3/etc/phpwebcounter/phpwebcounter.config.php");
require("/path/to/functions/file.php");

hits_webcounter($webcounter_id,$path_hits_file,$visible,$path_images,$counter_pad, $step);

if ($banner == '1') {
$body = <<<EOF
<br><a href="http://phpwebcounter.sourceforge.net"><font size=1px>PHP Web Counter</a></font size><br>
EOF;
}
 

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
hehe.. i'd do <br /> instead of <br> tho.. and maybe a little larger font size :yikes @ 1px:

damn, i'm a html syntax nazi laugh

/me hangs head in shame...

Joined: Jun 2006
Posts: 2
S
stranger
stranger
S Offline
Joined: Jun 2006
Posts: 2
Well, I emailed the authors of the hit counter. They told me to do this, which worked perfectly!

<div style="text-align: center;">
<?php require("../../etc/phpwebcounter/phpwebcounter.php"); ?></div>

Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
Nice and simple wink


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
PHP 8 bug in membermanage.tmpl
by phoenix011235 - 09/08/2026 7:47 PM
Are any of these legitmate?
by Baldeagle - 09/06/2026 1:37 PM
After server reboot
by Morgan - 09/02/2026 8:27 AM
Email Settings
by Outdoorking - 05/13/2026 2:44 AM
Who's Online Now
0 members (), 118 guests, and 136 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Ride safe!
Ride safe!
by Morgan, December 7
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260527)