Current location: Hot Scripts Forums » Programming Languages » PHP » counter, fgets() error..


counter, fgets() error..

Reply
  #1 (permalink)  
Old 05-22-04, 02:04 PM
j0hnbanks j0hnbanks is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
counter, fgets() error..

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;

?>
Reply With Quote
  #2 (permalink)  
Old 05-23-04, 05:03 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
when ever you are passing a a resource handle, NEVER put it inside double quotes!
this line was expecting a resource handle:
PHP Code:

$count fgets("$logfile"8); 

but instead, you gave him a weird string !!
note that when you put the variable inside double quotes, you are converting it into a string!
so this one should work:
PHP Code:

$count fgets($logfile8); 

I can see that in your code, you are putting all variables inside quotes, it's not a good practice ..
always when you pass arguments to function which are stored into variables, don't duoble quotes them..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 05-23-04 at 05:11 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Java: weird main error msg hecresper Everything Java 2 02-10-04 03:03 PM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM
parse error... help? kappler0 PHP 2 01-21-04 03:57 AM
[php error] parse error | fatal error xeoHosting PHP 1 01-03-04 08:12 PM
IP logging error in hit counter melllis ASP 2 10-02-03 06:25 PM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.