I set up a hitcounter so that each time someone goes to my site, one of 7 different sidebars loads up. There is a file called counter.php that writes to a text file called hitcounter.txt. All the references to files seem to be relative but when I moved them to a new directory at my new host I got this error instead of a happy hit counter:
<b>Warning</b>: fopen(hitcounter.txt) [<a href="function.fopen">function.fopen</a>]: failed to open stream: Permission denied in <b>/usr/local/apache/sites/MY-SITE/counter.php</b> on line <b>5</b><br>
Counter.php is pasted in its entirety below, line 5 is the first reference to fopen, both counter.php and hitcounter.txt have 775 permissions, same as they did on the old host.
What am I doing wrong? I'm obviously missing something really simple and embarrassing, so feel free to give me any scorn or abuse with while helping me out.
counter.php:
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
if ($fp) {
fputs($fp , "$hits[0]");
fclose($fp);
}
if($hits[0]<=1)
{
$random_number=0;
}
else if($hits[0]>1 && $hits[0]<=2)
{
$random_number=1;
}
else if($hits[0]>2 && $hits[0]<=3)
{
$random_number=2;
}
else if($hits[0]>3 && $hits[0]<=4)
{
$random_number=3;
}
else if($hits[0]>4 && $hits[0]<=5)
{
$random_number=4;
}
else if($hits[0]>5 && $hits[0]<=6)
{
$random_number=5;
}
else if($hits[0]>6 && $hits[0]<=7)
{
$random_number=6;
}
else if($hits[0]>7 && $hits[0]<=8)
{
$random_number=7;
}
else if($hits[0]>8 && $hits[0]<=9)
{
$random_number=8;
if($hits[0]==9)
{
$count_my_page=("hitcounter.txt");
$fp = fopen($count_my_page , "w");
$hits[0]=0;
fputs($fp , "$hits[0]");
fclose($fp);
}
}
?>