counter error (newbie)

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

Post Reply
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

counter error (newbie)

Post 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 :? :cry:
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

errmm.. please post the errors?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

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 »

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
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

Post 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 ...
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

Post 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 ?
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

Try putting the chmod of the directory its in to 777.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is there a reason to not use a database for this?
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

Post by buddok »

ermmmmm..... yer :roll: im lazy :P



but why ? are databases better for counters ?


o an i have already tried changin it to 777 same errors but thanx ....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

Post 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 :P ) and changed it there but thanks to one and all..... \m/
Post Reply