PDA

View Full Version : Web Counter


ecjoyce
09-06-2006, 02:27 PM
I have just added a hit counter to my website. I was wondering if I switch it to another hosting company will the coding transfer over or will I have to get a different counter? Thanks.

redsox9
09-06-2006, 03:16 PM
Hi, ecjoyce:

Whether the counter continues to work on your page depends on whether you host it locally or if it's called from another site / server. Is it BlueHost-specific? Do you have the URL of the page that contains the counter?

More details, please... :confused:

ecjoyce
09-06-2006, 03:57 PM
redsox,
I just took the html from the bluehost tools section. I guess that would mean that it is BlueHost specific. Do you know if this will still transfer? If not can you recommend a good global site to get counters. Thanks.

ecjoyce

redsox9
09-06-2006, 06:14 PM
Hi, ecjoyce:

Well, if it's from the BlueHost tools section then probably not. Do a search on hit counters in Google and there are tons of other sites that offer free counters with stats, etc. I honestly can't recommend one but I'm sure almost any will work - maybe someone else says different?

dkinzer
09-06-2006, 09:03 PM
If your site is coded in php it is fairly easy to add a text-based hit counter. With more work, you could display it in one of the fancy "odometer" styles.
<?php
$dfile = "hit_count.txt";
if (file_exists($dfile))
{
// read the last hit count and increment it
$fp = fopen($dfile, "r");
$count = fread($fp, 10);
$count = (int)$count;
$count++;
fclose($fp);
$fp = fopen($dfile, "w");
fputs($fp, $count);
fclose($fp);

// determine proper ordinal suffix
$rem = $count % 10;
if (($rem >= 1) && ($rem <= 3)) {
if ((($count % 100) >= 11) && (($count % 100) <= 13)) {
$suffix = "th";
} else {
switch ($rem)
{
case (1):
$suffix = "st";
break;

case (2):
$suffix = "nd";
break;

case (3):
$suffix = "rd";
break;

default:
$suffix = "";
break;
}
}
} else {
$suffix = "th";
}

// display the hit count message
echo '<p><br><font size="-2"><b><em>You are the</em> ' . $count . $suffix . "<em> visitor since 01 January 2006.</em></b></font></p>\n";
}
?>
To use this you have to create a file in the same directory as this script that is named hit_count.txt. It can be empty initially and thereafter it will contain the hit count.