I'm trying to make a simple text counter for my site, and this is the problem that I am running into, all dirs that this is linked to are set to 777 to remove all problems and the pather are all correct, but for some reason this one line is causing a problem, what am i missing??
This is the error that I am getting:
Warning: fgets(): supplied argument is not a valid stream resource in /storage/bandm/public_html/count.php on line 54
Line 54 says:
$count = fgets("$logfile", 8);
Here is my code, what is the problem with it?:
<?
$datadir = "/storage/bandm/public_html/counters/";
$snoop = 1;
if(phpversion() >= "4.2.0"){
extract($_POST);
extract($_SERVER);
extract($_ENV);
}
function do_snoop($datadir,$REMOTE_ADDR,$HTTP_USER_AGENT,$H TTP_REFERER,$REQUEST_URI)
{
$filename = str_replace("/","_",$REQUEST_URI);
if ( (substr($filename, -1)) == "_" )
$filename .= "index";
$date = date("m/d/Y h:i:s A");
$logfile = fopen("$datadir" . "$filename" . "-info.txt", "a+");
fputs("$logfile", $date . "\t" . $REMOTE_ADDR . "\t" . $HTTP_USER_AGENT . "\t " . $HTTP_REFERER . "\n");
fclose($logfile);
}
$filename = str_replace("/","_",$REQUEST_URI);
if ( (substr($filename, -1)) == "_" )
$filename .= "index";
$filetest = file_exists( "$datadir" . "$filename");
if (!$filetest)
{
$logfile = fopen( "$datadir" . "$filename", "w");
if (!$logfile)
exit;
else
{
$count += 1;
fputs("$logfile", $count);
fclose("$logfile");
exit;
}
}
else
$logfile = fopen("$datadir" . "$filename", "r+");
if (!$logfile)
exit;
else
{
$count = fgets("$logfile", 8);
if (!$count)
exit;
else
{
$count += 1;
echo "<font face=\"verdana\" size=2 color=\"#000000\"> $count </font>";
fseek("$logfile", 0);
fputs("$logfile", $count);
fclose($logfile);
}
}
if ($snoop==1) do_snoop($datadir,$REMOTE_ADDR,$HTTP_USER_AGENT,$H TTP_REFERER,$REQUEST_URI);
exit;
?>