7 Replies - 1611 Views - Last Post: 17 March 2002 - 08:04 PM Rate Topic: -----

#1 elite eagle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 03-January 02

this script wont work!!! why???

Posted 15 March 2002 - 11:11 PM

hey there, i made this php counter for my site but it deosnt seem to work, well it worked once and incremented the counter by one the first time but it fails to work again. could someone look over my code and see why its not working? thanks

btw the script is at http://www.aombf.com/counter.php

code(i added comments to make it easier to understand):

<html>
<head>
<title>Counter</title>
</head>
<body>
<?php
//file pointer for reading counter file
$fileptread=fopen("countervar.txt","r");
//the counter variable equals whatever variable is in the .txt file
$counternum=fgets($fileptread, 10000);
//close the reading connection
fclose($fileptread);
//increase the counter variable with every execution of the script
$counternum++;
//file pointer for entering data into the counter file
$fileptput=fopen("countervar.txt","r");
//now change the counter variable in the .txt file to the new increased value
fputs($fileptput,$counternum);
//close entering connection with .txt file
fclose($fileptput);
//print the counter value
printf("Visitars: %'010d",$counternum);
?>
</body>
</html>

(Edited by elite eagle at 1:11 am on Mar. 16, 2002)


(Edited by elite eagle at 1:12 am on Mar. 16, 2002)

(Edited by elite eagle at 1:13 am on Mar. 16, 2002)


Is This A Good Question/Topic? 0
  • +

Replies To: this script wont work!!! why???

#2 LammaDog  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 30-September 01

Re: this script wont work!!! why???

Posted 16 March 2002 - 02:50 AM

That's funny, I just did the same thing last night for http://snippets.lammadog.com

when you open the countervar.txt file the second time to put in the new number, you have to open for for write instead of read.

like this...
$fileptput=fopen("countervar.txt","w");

(Edited by LammaDog at 4:58 am on Mar. 16, 2002)

Was This Post Helpful? 0
  • +
  • -

#3 elite eagle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 03-January 02

Re: this script wont work!!! why???

Posted 16 March 2002 - 09:37 AM

yeah that was my mistake, however when i change that i get this page now and it still deosnt work...

Visitars: 0000000001
Warning: fopen("countervar.txt", "w") - Permission denied in /home/aombfco/public_html/counter.php on line 18

Warning: Supplied argument is not a valid File-Handle resource in /home/aombfco/public_html/counter.php on line 20

Warning: Supplied argument is not a valid File-Handle resource in /home/aombfco/public_html/counter.php on line 22


wierd

(Edited by elite eagle at 11:40 am on Mar. 16, 2002)

Was This Post Helpful? 0
  • +
  • -

#4 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: this script wont work!!! why???

Posted 16 March 2002 - 09:53 AM

You need to CHMod 777 the .txt file so that the script can use it.  See if that helps. . . :D
Was This Post Helpful? 0
  • +
  • -

#5 iordy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 05-March 02

Re: this script wont work!!! why???

Posted 17 March 2002 - 08:46 AM

(chmod 777)'ing everything is not the best habbit to get into and in this instace 666 will do just fine. Even better if you have access to your webserver either because it's in your own or you can telnet|ssh into it.

Change the user:group to nobody:nogroup (your milage may vary depending on the admin for the default user:group on the webserver).
example:

chown nobody:nogroup countervar.txt
chmod 600 countervar.txt

But if you arn't that fussed about leaving files all over the place with 'rwx' permissions for everyone then just 777 everything. It's simple and you dont have to understand what it does.

(Edited by iordy at 10:47 am on Mar. 17, 2002)

Was This Post Helpful? 0
  • +
  • -

#6 elite eagle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 03-January 02

Re: this script wont work!!! why???

Posted 17 March 2002 - 01:49 PM

thanks, thats probably it, but i have no idea what chmod is?
Was This Post Helpful? 0
  • +
  • -

#7 Sem  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 199
  • Joined: 10-February 02

Re: this script wont work!!! why???

Posted 17 March 2002 - 05:22 PM

Quote

Quote: from elite eagle on 1:49 pm on Mar. 17, 2002
thanks, thats probably it, but i have no idea what chmod is?

CHMOD allows you to set file permisions (whether the file can be read, written to, or executed)

What FTP program are you using? Try right-clicking on the file, and looking for CHMOD in the context menu. If your FTP proggy is anything like WS_FTP, a window will appear that allows you to set the CHMOD.

I'm not 100% positive on this, but I believe it only works on *nix servers. I've never had a Windows host, so I'm not sure :shrugs:

Sem

(Edited by Sem at 5:23 pm on Mar. 17, 2002)

Was This Post Helpful? 0
  • +
  • -

#8 elite eagle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 03-January 02

Re: this script wont work!!! why???

Posted 17 March 2002 - 08:04 PM

YES, THATS IT!!! IT WORKS!!!!! YOU GUYS ARE THE BOMB!!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1