View Full Version : Errm..
For some reason today I know have this error alot on my site:
Warning: Division by zero in /home/habfancl/public_html/index.php on line 199
And my hit counter dont work :S
Line 199:
$percentage=($uptime/$days) * 100;
Hit counter code:
<?php
$path = "images/";
$ext = ".gif";
$file = "counter.dat";
$file_array = file($file);
$hits = $file_array[0];
$hits++;
$fp = fopen($file, "w");
fputs($fp, $hits);
fclose($fp);
for ( $i = 0; $i <= 9; $i++ ) {
$hits = str_replace($i, "<img src=\"$path$i$ext\" alt=\"$i\" />", $hits);
}
echo $hits;
?>
$percentage=($uptime/$days) * 100;
The uptime or days are zero?
Use this for your counter:
<?PHP
$viewsfile = file('hits.txt'); //Hits text file name
$views = $viewsfile[0];
if ($views != 0)
{
$views++;
$open = fopen('hits.txt', 'w'); //Hits text file name
fwrite($open, $views);
fclose($open);
}
else
{
echo 'An error occurred. Please check the value of your hits text file is not zero or lower.';
exit;
};
echo $views;
?>
The uptime or days are zero?
Use this for your counter:
<?PHP
$viewsfile = file('hits.txt'); //Hits text file name
$views = $viewsfile[0];
if ($views != 0)
{
$views++;
$open = fopen('hits.txt', 'w'); //Hits text file name
fwrite($open, $views);
fclose($open);
}
else
{
echo 'An error occurred. Please check the value of your hits text file is not zero or lower.';
exit;
};
echo $views;
?>
I want images though :(
Luckyrare
01-01-2006, 01:31 PM
I want images though :(
Well you could use the code Nets gave you and have a look at GD if you want images so bad ;P
www.php.net/gd
Dan Williamson
01-01-2006, 03:17 PM
Exactly.
Use a GD too display it. But Nets script looks ok.
- Dan
Nets your script dont work :S I have cmoded the files to 777 but it still dont work. It displays but wont increase.
timROGERS
02-01-2006, 12:26 PM
I gotta try out GD one of these days :P
Nets your script dont work :S I have cmoded the files to 777 but it still dont work. It displays but wont increase.
Put the number as 1 to start with, it doesn't do anything if it is 0 so that it doesn't write over the file with 0 if the file didn't load.
Put the number as 1 to start with, it doesn't do anything if it is 0 so that it doesn't write over the file with 0 if the file didn't load.
But i dont want it as 1 i want it as 10578 witch it is set as.
But i dont want it as 1 i want it as 10578 witch it is set as.
Erm it should work fine if you type in 10578..
Erm it should work fine if you type in 10578..
It dont :(
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.