Re: why does this simple counter fail?



On Fri, Mar 25, 2011 at 06:36:34AM -0500, Ryan Coleman wrote:
You're using a completely stock php.ini file.

Look for short tags. Turn that on.

<?php is long form... most scripts are using short tags.

I don't see why you need the file name in the file itself... just have a number there. Much faster on the CPU.


True enough. I could have everything in one file and simply
print the filename and number. I didn't know that I had the
option of using short flags or not. Where do I set that? (I'm
sure there are more places where i have "<?" anf "?>" rather
than "<?php" and "?>"; be nice to _not_ have this cause me grief
again....)

tx,

gary



--
Ryan

On Mar 25, 2011, at 12:36 AM, Gary Kline wrote:

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 "<?" rather than
"<?php"

gary




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 <kline@xxxxxxxxxxx> 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 "<?" <cr> instead of "<?php"> <cr>. 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"

--
Gary Kline kline@xxxxxxxxxxx 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



--
Gary Kline kline@xxxxxxxxxxx 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



--
Gary Kline kline@xxxxxxxxxxx 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: why does this simple counter fail?
    ... Look for short tags. ... On Mar 25, 2011, at 12:36 AM, Gary Kline wrote: ... hack with no error-checking is that i have used the same script ... PHP), not a shared lock. ...
    (freebsd-questions)
  • Re: why does this simple counter fail?
    ... On Mar 25, 2011, at 11:44 AM, Gary Kline wrote: ... Look for short tags. ... hack with no error-checking is that i have used the same script ... PHP), not a shared lock. ...
    (freebsd-questions)
  • Re: why does this simple counter fail?
    ... in directory countdir, in file index is: ... hack with no error-checking is that i have used the same script ... On Mar 24, 2011, at 6:00 PM, Gary Kline wrote: ... PHP), not a shared lock. ...
    (freebsd-questions)
  • Re: why does this simple counter fail?
    ... There were no errors that should up when i launched this script ... ...Another php ... On Mar 23, 2011, at 11:45 AM, Gary Kline wrote: ... The 7.98a release of Jottings: http://jottings.thought.org ...
    (freebsd-questions)
  • Re: PHP Always Outputs
    ... Is there a setting somewhere in my php or apache config that ... If he wants to be able to add tags in the HEAD ... HTML code itself would be fine. ... If the prepended file is just HTML code, not a PHP script, then ...
    (comp.lang.php)