RE: [PHP] file permissions on counter?

From: Date: Thu, 25 Apr 2002 00:51:33 +0000
Subject: RE: [PHP] file permissions on counter?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-94459@lists.php.net to get a copy of this message
I would add some file locking to your code to make it more reliable. If you start having a lot of traffic, your code will start missing people. www.php.net/flock ---John Holmes... > -----Original Message----- > From: Tyler Longren [mailto:tyler@captainjack.com] > Sent: Tuesday, April 23, 2002 8:44 PM > To: Antonio; php-general@lists.php.net > Subject: Re: [PHP] file permissions on counter? > > Hi Antonio, > > try this for your fopen(): > $file=fopen("counter.txt","r+") > > Incase you're interested, here's the code I use whenever I need to use a > simple text-file based counter: > <? > $file = ".count.txt"; > $fp = fopen("$file","r+"); > $counter = fread($fp, filesize("$file")); > fclose($fp); > $counter +=1; > $fp = fopen("$file", "w+"); > fputs($fp, $counter); > fclose($fp); > include("$file"); > ?> > > Tyler Longren > Captain Jack Communications > www.captainjack.com > tyler@captainjack.com > > ----- Original Message ----- > From: "Antonio" <info@pcelche.com> > To: <php-general@lists.php.net> > Sent: Tuesday, April 23, 2002 8:48 PM > Subject: [PHP] file permissions on counter? > > > > Hi, I have to read a simple counter on my server, but the server > > responses that I haven't permissions to open the file which contains the > > data in write mode. This file (counter.txt) it has all the permissions > > (777). I don't know how to do, could somebody help me? > > > > > > I execute this file on server: > > > > > > <HTML> > > <HEAD> > > <TITLE></TITLE> > > <BODY> > > > > > > <?php > > > > > > $userip = $REMOTE_ADDR; > > > > > > if ($file=fopen("counter.txt", "w")) { > > $counter = fread($file, 10); > > $counter++; > > fwrite($file , $counter); > > fclose($file); > > } > > > > echo $counter; > > > > > > ?> > > > > > > </body> > > </html> > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#94459) next »