PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Fri Aug 13, 2004 10:31 am
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
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Fri Aug 13, 2004 11:06 am
errmm.. please post the errors?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Fri Aug 13, 2004 11:22 am
Most likely need to set the proper chmod on the file.
Use [php_man]chmod[/php_man]() or set it manually.
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Fri Aug 13, 2004 11:40 am
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
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Fri Aug 13, 2004 11:59 am
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 ...
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Fri Aug 13, 2004 12:07 pm
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 ?
dwfait
Forum Contributor
Posts: 113 Joined: Sun Aug 01, 2004 10:36 pm
Post
by dwfait » Fri Aug 13, 2004 12:13 pm
Try putting the chmod of the directory its in to 777.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 12:15 pm
is there a reason to not use a database for this?
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Fri Aug 13, 2004 12:17 pm
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 ....
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 12:22 pm
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..
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Fri Aug 13, 2004 12:27 pm
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/