Page 1 of 1
counter error (newbie)
Posted: Fri Aug 13, 2004 10:31 am
by buddok
hey ppl can any one help me with my counter it wont work properly?
Code: Select all
<?php
$counter_file = ("mycount.txt");
$visits = file($counter_file);
$visits[0]++;
$fp = fopen($counter_file , "w");
fputs($fp , "$visits[0]");
fclose($fp);
echo $visits[0];
?>
it comes up with these errors and those warning things

Posted: Fri Aug 13, 2004 11:06 am
by d3ad1ysp0rk
errmm.. please post the errors?
Posted: Fri Aug 13, 2004 11:22 am
by m3mn0n
Most likely need to set the proper chmod on the file.
Use [php_man]chmod[/php_man]() or set it manually.
Posted: Fri Aug 13, 2004 11:40 am
by Getran
this works:
Code: Select all
<?php
chmod("counter.txt", 0644);
$counter = ("counter.txt");
$visits = file($counter);
$visits[0]++;
$add = $visits[0];
$fp = fopen($counter , "w");
fputs($fp, $add);
fclose($fp);
echo $add;
?>
make sure in counter.txt, it only has '0' in there nothing else
Posted: Fri Aug 13, 2004 11:59 am
by buddok
yo sami i think i need to do the thing u mentioned it says somthin about 777 and that thing u sed

but i didnt get that bit

ahwell ill jus the script above thanks all ...
Posted: Fri Aug 13, 2004 12:07 pm
by buddok
ok i tried the script above and im still getting these errors ?
these are the errors:
Warning: chmod() [function.chmod]: Operation not permitted in /home/dontnow/public_html/counter.php on line 2
Warning: fopen(counter.txt) [function.fopen]: failed to create stream: Permission denied in /home/dontnow/public_html/counter.php on line 7
Warning: fputs(): supplied argument is not a valid stream resource in /home/dontnow/public_html/counter.php on line 8
Warning: fclose(): supplied argument is not a valid stream resource in /home/dontnow/public_html/counter.php on line 9
anyone have any suggestions ?
Posted: Fri Aug 13, 2004 12:13 pm
by dwfait
Try putting the chmod of the directory its in to 777.
Posted: Fri Aug 13, 2004 12:15 pm
by feyd
is there a reason to not use a database for this?
Posted: Fri Aug 13, 2004 12:17 pm
by buddok
ermmmmm..... yer

im lazy
but why ? are databases better for counters ?
o an i have already tried changin it to 777 same errors but thanx ....
Posted: Fri Aug 13, 2004 12:22 pm
by feyd
you wouldn't have these file access problems, and databases are generally safer for handling simultaneous access and updates of things like these..
with what you have here, there's the potential for 2 accesses to happen at the same time, which would result in the file getting written as the same number, even though there were 2 different accesses..
Posted: Fri Aug 13, 2004 12:27 pm
by buddok
hey everyone thanks alot for your help ive figured it now... i just went into the properties of the .txt fiel in smatFTP and changed it there (
which i never knew i could do
) and changed it there but thanks to one and all..... \m/