My php counter is sick
Not sure what's going on.
I get this error message:
Warning: fopen("counterlog_uh_index.txt","w") - Permission denied in counter_uh.php on line 45
Warning: Unable to find file identifier 0 in counter_uh.php on line 47
Warning: Unable to find file identifier 0 in counter_uh.php on line 48
I think this means it won't open the file counterlog_uh_index.txt. Thing is, I have about 12 other page counters that are accessing the same counter_uh.php file and are having no problems. Not sure why counterlog_uh_index.txt is cursed?
Anyway, here's the code of the page that displays the error:
<?php
/*
//Total hits counter
$filename_th = "counterlog_th.txt";
require("counter_th.php");
*/
//Unique hits counter
$filename = "counterlog_uh_index.txt" ;
$filename1 = "counterlog_uh.txt" ;
require("counter_uh.php");
?>
Here's the code for the counter_uh.php file:
<?php
//Unique_array function
function array_unique(&$thearray)
{sort($thearray);
reset($thearray);
$newarray = array();
$i = 0;
$element = current($thearray);
for ($n=0;$n<sizeof($thearray);$n++)
{if (next($thearray) != $element)
{$newarray[$i] = $element;
$element = current($thearray);
$i++;
}
}
$thearray = $newarray;
}
//Unique hits counter
$startdate = "December 2002" ;
$ip = getenv("REMOTE_ADDR") ;
$currentip = "$ip";
$file = file($filename);
$file = array_unique($file);
$file = "$filename";
$fd = fopen ($file, "r");
$fget= fread ($fd, filesize ($file));
fclose ($fd);
$totalips = htmlspecialchars($fget);
if (preg_match ("/$ip/i", "$totalips")) {
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
} else {
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring.$currentip."\n";
$fout= fwrite ($fd , $fcounted);
fclose($fd);
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
}
//Unique hits counter for total
$startdate1 = "December 2002" ;
$ip1 = getenv("REMOTE_ADDR") ;
$currentip1 = "$ip";
$file1 = file($filename1);
$file1 = array_unique($file1);
$file1 = "$filename1";
$fd1 = fopen ($file1, "r");
$fget1= fread ($fd1, filesize ($file1));
fclose ($fd1);
$totalips1 = htmlspecialchars($fget1);
if (preg_match ("/$ip1/i", "$totalips1")) {
$file1 = file($filename1);
$file1 = array_unique($file1);
$hits1 = count($file1);
} else {
$fd1 = fopen ($filename1 , "r");
$fstring1 = fread ($fd1 , filesize ($filename1)) ;
fclose($fd1) ;
$fd1 = fopen ($filename1 , "w");
$fcounted1 = $fstring1.$currentip1."\n";
$fout1= fwrite ($fd1 , $fcounted1);
fclose($fd1);
$file1 = file($filename1);
$file1 = array_unique($file1);
$hits1 = count($file1);
}
?>
The unique_array function at the top is there because my ISP uses php3 only.
Well, it's got me stumped. As I said, all my other counters are working fine so I can't understand what the problem is. Here's one of the counters that's working (I can't see any difference):
<?php
//Unique hits counter
$filename = "counterlog_uh_eve_banners.txt" ;
$filename1 = "counterlog_uh.txt" ;
require("counter_uh.php");
?>
Also the CHMOD permissions on the files are all the same: Owner, group and other are all set to "read", and just owner is set for "write"; none are set to "execute".
Thx if you can help.Try setting the permissions to 777 or 666, this comes to my mind when I see the error.
Good Luck,
Paulcorrect Paul,
b1, set the permissions to "counterlog_uh_index.txt"
the error on that one is creating the other 2 errors.
Not sure what's going on.
I get this error message:
Warning: fopen("counterlog_uh_index.txt","w") - Permission denied in counter_uh.php on line 45
Warning: Unable to find file identifier 0 in counter_uh.php on line 47
Warning: Unable to find file identifier 0 in counter_uh.php on line 48
I think this means it won't open the file counterlog_uh_index.txt. Thing is, I have about 12 other page counters that are accessing the same counter_uh.php file and are having no problems. Not sure why counterlog_uh_index.txt is cursed?
Anyway, here's the code of the page that displays the error:
<?php
/*
//Total hits counter
$filename_th = "counterlog_th.txt";
require("counter_th.php");
*/
//Unique hits counter
$filename = "counterlog_uh_index.txt" ;
$filename1 = "counterlog_uh.txt" ;
require("counter_uh.php");
?>
Here's the code for the counter_uh.php file:
<?php
//Unique_array function
function array_unique(&$thearray)
{sort($thearray);
reset($thearray);
$newarray = array();
$i = 0;
$element = current($thearray);
for ($n=0;$n<sizeof($thearray);$n++)
{if (next($thearray) != $element)
{$newarray[$i] = $element;
$element = current($thearray);
$i++;
}
}
$thearray = $newarray;
}
//Unique hits counter
$startdate = "December 2002" ;
$ip = getenv("REMOTE_ADDR") ;
$currentip = "$ip";
$file = file($filename);
$file = array_unique($file);
$file = "$filename";
$fd = fopen ($file, "r");
$fget= fread ($fd, filesize ($file));
fclose ($fd);
$totalips = htmlspecialchars($fget);
if (preg_match ("/$ip/i", "$totalips")) {
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
} else {
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring.$currentip."\n";
$fout= fwrite ($fd , $fcounted);
fclose($fd);
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
}
//Unique hits counter for total
$startdate1 = "December 2002" ;
$ip1 = getenv("REMOTE_ADDR") ;
$currentip1 = "$ip";
$file1 = file($filename1);
$file1 = array_unique($file1);
$file1 = "$filename1";
$fd1 = fopen ($file1, "r");
$fget1= fread ($fd1, filesize ($file1));
fclose ($fd1);
$totalips1 = htmlspecialchars($fget1);
if (preg_match ("/$ip1/i", "$totalips1")) {
$file1 = file($filename1);
$file1 = array_unique($file1);
$hits1 = count($file1);
} else {
$fd1 = fopen ($filename1 , "r");
$fstring1 = fread ($fd1 , filesize ($filename1)) ;
fclose($fd1) ;
$fd1 = fopen ($filename1 , "w");
$fcounted1 = $fstring1.$currentip1."\n";
$fout1= fwrite ($fd1 , $fcounted1);
fclose($fd1);
$file1 = file($filename1);
$file1 = array_unique($file1);
$hits1 = count($file1);
}
?>
The unique_array function at the top is there because my ISP uses php3 only.
Well, it's got me stumped. As I said, all my other counters are working fine so I can't understand what the problem is. Here's one of the counters that's working (I can't see any difference):
<?php
//Unique hits counter
$filename = "counterlog_uh_eve_banners.txt" ;
$filename1 = "counterlog_uh.txt" ;
require("counter_uh.php");
?>
Also the CHMOD permissions on the files are all the same: Owner, group and other are all set to "read", and just owner is set for "write"; none are set to "execute".
Thx if you can help.Try setting the permissions to 777 or 666, this comes to my mind when I see the error.
Good Luck,
Paulcorrect Paul,
b1, set the permissions to "counterlog_uh_index.txt"
the error on that one is creating the other 2 errors.