Hello all! I have just downloaded all my files from my server onto my computer ready to have a quick browse through and clean up scripts/remove unnecessary pages. I have Apache, MySQL and PHP running on my computer so I can test before re-uploading. At the moment I have downloaded my front page, which includes a very basic page counter. The page counter is working perfectly fine online, in the live environment, but not on my testing environment. The only thing I can think of for this error, is that I am using PHP5, and there is a chance my host company is using something different - different version of 5 or whatever.
There are two parts to this counter system: count.php and hitcounter.dat
hitcounter.dat is just a text file with a number, which increases with each page hit
count.php is the coding that calls the files, displays it and edits it. I include the count.php page on my index page. It should just display the number in the hitcounter.dat file
I was just wondering if someone might be able to point me in the right direction for sorting it out. There is an 'if you can't find what you want, return this error message' built into the system, but the error message I get seems to go above and beyond that! This is my current message:
Error, could not find hitcounter.dat in ".$path.", please check it!
"; } if($formatnumber) { $count_new = number_format($count, 2, ",", ","); $count_new = substr($count_new, 0 , -3); $count = $count_new; } if($showimage) { $width = imagefontwidth($font) * strlen($count); $height = imagefontheight($font); $im = @imagecreate($width, $height); if(trim($bgcolor) == "black") $background_color = imagecolorallocate($im, 0, 0, 0); // black background else { $background_color = imagecolorallocate($im, 255, 255, 255); //white background imagecolortransparent($im, $background_color); } if(trim($fontcolour) == "black") $text_color = imagecolorallocate($im, 0, 0, 0); // black text else $text_color = imagecolorallocate($im, 255, 255, 255); // white text imagestring($im, $font, 0, 0, $count, $text_color); header("Content-type: image/gif"); imagegif($im); imagedestroy($im); } else { print $count; } ?>
This is the original count.php code:
<?
$formatnumber = true; // add thousands separator? false disables it.
// ONLY EDIT BELOW IF YOU WANT AN HIT COUNTER RENDERED AS AN IMAGE
$showimage = false; // change to true to enable image render
$font = 2; // font style, 1-5. These are built in php fonts!
$fontcolour = "black"; // black or white font?
$bgcolor = "transparent"; // transparent or black background?
// DO NOT EDIT BELOW THIS LINE - DO THE CUSTOMISING IN THE PAGE YOU INCLUDE ON! //
$path = __FILE__;
$path = preg_replace( "'\\\count\.php'", "", $path);
$path = preg_replace( "'/count\.php'", "", $path);
$counter = $path."/hitcounter.dat";
if(file_exists($counter))
{
$fp = fopen($counter, "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
}
else
{
print "<p>Error, could not find hitcounter.dat in ".$path.", please check it!</p>";
}
if($formatnumber)
{
$count_new = number_format($count, 2, ",", ",");
$count_new = substr($count_new, 0 , -3);
$count = $count_new;
}
if($showimage)
{
$width = imagefontwidth($font) * strlen($count);
$height = imagefontheight($font);
$im = @imagecreate($width, $height);
if(trim($bgcolor) == "black")
$background_color = imagecolorallocate($im, 0, 0, 0); // black background
else
{
$background_color = imagecolorallocate($im, 255, 255, 255); //white background
imagecolortransparent($im, $background_color);
}
if(trim($fontcolour) == "black")
$text_color = imagecolorallocate($im, 0, 0, 0); // black text
else
$text_color = imagecolorallocate($im, 255, 255, 255); // white text
imagestring($im, $font, 0, 0, $count, $text_color);
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
}
else
{
print $count;
}
?>
I have been into the coding and removed the <p> and </p> in the echo string, which improves things. The error message has now disappeared. However, instead of getting "1234 visitors since January 2006", I am just getting "visitors since January 2006". Originally the error was mentioning that $path was wrong. I am pretty sure it is going to be something simple and easy to fix. I wonder if there was a switch in directory naming conventions that may be causing it not to recall and display the file?
As I say, it works perfectly fine in the live environment and my website is merrily ticking over nicely; it would just be nice to get it fully functional in my test environment. I am guessing that it could be 1) a coding issue; 2) out of date testing environment (although I'm sure my PHP is more up-to-date than my host!); 3) something to do with my testing environment not recognising the file format?; or 4) none of the above!!!
Anyway, thank you in advance to anyone who can throw some light onto the issue! 😃