From owner-freebsd-questions@FreeBSD.ORG Fri Mar 25 05:36:32 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49B4F1065670 for ; Fri, 25 Mar 2011 05:36:32 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (plato.thought.org [209.180.213.209]) by mx1.freebsd.org (Postfix) with ESMTP id F2B348FC0A for ; Fri, 25 Mar 2011 05:36:31 +0000 (UTC) Received: by thought.org (Postfix, from userid 1001) id C46A0E80979; Thu, 24 Mar 2011 22:36:30 -0700 (PDT) Date: Thu, 24 Mar 2011 22:36:30 -0700 From: Gary Kline To: Ryan Coleman Message-ID: <20110325053630.GA6722@thought.org> References: <20110323164504.GA25317@thought.org> <20110324230049.GB31958@thought.org> <89898D0E-B4A9-41E9-B829-DF7CA8D3FF06@d3photography.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <89898D0E-B4A9-41E9-B829-DF7CA8D3FF06@d3photography.com> X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 24++ years of service to the Unix community. User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Fr?d?ric Perrin , freebsd-questions@freebsd.org Subject: Re: why does this simple counter fail? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2011 05:36:32 -0000 On Thu, Mar 24, 2011 at 06:25:39PM -0500, Ryan Coleman wrote: > Gary, you missed the put... fput($fp, $file); means you're dropping the filename INTO the storage file. okay. [maybe]. i think what the script does is create ./countdir/$file ; in this case, ./countdir/index where i create the file named "index\n" and below it the integer count. e.g.: in directory countdir, in file index is: index 60311 to track the hits for my homepage. in defense of this crude hack with no error-checking is that i have used the same script in at least three other virtual thought.org websites. i was wrong is saying that the script bombed; it just failed; the reason was that the initial tag had been " > > On Mar 24, 2011, at 6:00 PM, Gary Kline wrote: > > > On Wed, Mar 23, 2011 at 07:11:15PM +0100, Fr?d?ric Perrin wrote: > >> Gary Kline writes: > >>> Can any of you php hackers tell me why this simple self-hacked > >>> counter bomb? > >> > >> As others said, what does 'this simple counter bomb' means? > >> > >>> $fp = fopen($directory.$file, "r+"); > >>> flock($fp, 1); > >> > >> You want an exclusive lock (LOCK_EX, which is 2 is you use some ancient > >> PHP), not a shared lock. > >> > >> When updating the file: > >> > fputs($fp, $count); > >> > fputs($fp, "\n"); > >>> fputs($fp, $file); > >> > >> Why do you feel the need to store the filename inside the file itself? > >> You don't seem to need it after. > > > > > > $file is passed from the calling php file. index.php is by-hand > > set to > > > > $file='index'; > > > > and so on. > > > > Because of my shoulder/typing woes, it was great that I got clued in > > above by Brad's thought that perhaos there were mis-matched " > and "?>" tags. A simply recursive grepping found out that it some > > places I had " instead of " . Adding the "php" > > fixed everything. > > > > Finally, you're right; this really, really is ancient php. > > Somthing i found pre-2004 and hacked until it worked. The > > counter is missings lots of features, but I'll fix that pretty > > soon. > > > > thanks to everybody , > > > > > >> > >> -- > >> Frédéric Perrin -- http://tar-jx.bz > >> > >> _______________________________________________ > >> freebsd-questions@freebsd.org mailing list > >> http://lists.freebsd.org/mailman/listinfo/freebsd-questions > >> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > > > > -- > > Gary Kline kline@thought.org http://www.thought.org Public Service Unix > > Journey Toward the Dawn, E-Book: http://www.thought.org > > The 7.98a release of Jottings: http://jottings.thought.org > > > > _______________________________________________ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix Journey Toward the Dawn, E-Book: http://www.thought.org The 7.98a release of Jottings: http://jottings.thought.org