Re: why does this simple counter fail?

2011-03-25 Thread Ryan Coleman
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.

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

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Gary Kline
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 kl...@thought.org 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@freebsd.org mailing list
  http://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to 
  freebsd-questions-unsubscr...@freebsd.org
  
  -- 
  Gary Kline  kl...@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-unsubscr...@freebsd.org
  
  
  
  -- 
  Gary Kline  kl...@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-unsubscr...@freebsd.org
 
 

-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Ryan Coleman
That would cause a lot of file hanging, with locking, if you get any decent 
amount of traffic... 

I'd just stick to the simple TXT counter for the time being.

If you did a mass file, your best bet would be to use arrays and serialize the 
data... but that's a lesson for another day.


On Mar 25, 2011, at 11:44 AM, Gary Kline wrote:

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


Re: why does this simple counter fail?

2011-03-25 Thread Frédéric Perrin
Gary Kline kl...@thought.org writes:
 On Fri, Mar 25, 2011 at 06:36:34AM -0500, Ryan Coleman wrote:
 Look for short tags. Turn that on.
 
 ?php is long form... most scripts are using short tags.

 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)

In /usr/local/etc/php.ini, look for short_open_tag under the « Language
Options » heading.

-- 
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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Gary Kline
On Fri, Mar 25, 2011 at 05:53:11PM +0100, Fr?d?ric Perrin wrote:
 Gary Kline kl...@thought.org writes:
  On Fri, Mar 25, 2011 at 06:36:34AM -0500, Ryan Coleman wrote:
  Look for short tags. Turn that on.
  
  ?php is long form... most scripts are using short tags.
 
  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)
 
 In /usr/local/etc/php.ini, look for short_open_tag under the « Language
 Options » heading.
 
 -- 
 Frédéric Perrin -- http://tar-jx.bz
 
Found it; thanks.   It's been god-knows how many yrs ago that i
used the short tags option  it may have been the Last time
my counter broke.  Lost in the myst of times.  Anyway, i've
decided to leave the short form off as is advised in the ini
file.  

I'M trying to decide whether to tatoo this on my forehead or
just make a note in my ~/.notes file for the next time this
breaks.  if/when.  Meanwhile, the best thingt to do would simply
write a script to turn ? into ?php    Never know when I'll
get into things like ?xml or whatever.

-g


-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Brad Mettee

Gary Kline wrote:

I'M trying to decide whether to tatoo this on my forehead or
just make a note in my ~/.notes file for the next time this
breaks.  if/when.  Meanwhile, the best thingt to do would simply
write a script to turn ? into ?php    Never know when I'll
get into things like ?xml or whatever.
  
If you do the ? into ?php, don't forget to do ?phpphp into ?php too. 
Otherwise you'll likely corrupt already good tags.



-- Brad
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Polytropon
On Fri, 25 Mar 2011 21:12:08 -0400, Brad Mettee bmet...@pchotshots.com wrote:
 Gary Kline wrote:
  I'M trying to decide whether to tatoo this on my forehead or
  just make a note in my ~/.notes file for the next time this
  breaks.  if/when.  Meanwhile, the best thingt to do would simply
  write a script to turn ? into ?php    Never know when I'll
  get into things like ?xml or whatever.

 If you do the ? into ?php, don't forget to do ?phpphp into ?php too. 
 Otherwise you'll likely corrupt already good tags.

With 's/\?$/\?php/g' and sufficient quoting,
maybe removing extra spaces, it should be fine. :-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-25 Thread Gary Kline
On Sat, Mar 26, 2011 at 02:30:09AM +0100, Polytropon wrote:
 On Fri, 25 Mar 2011 21:12:08 -0400, Brad Mettee bmet...@pchotshots.com 
 wrote:
  Gary Kline wrote:
 I'M trying to decide whether to tatoo this on my forehead or
 just make a note in my ~/.notes file for the next time this
 breaks.  if/when.  Meanwhile, the best thingt to do would simply
 write a script to turn ? into ?php    Never know when I'll
 get into things like ?xml or whatever.
 
  If you do the ? into ?php, don't forget to do ?phpphp into ?php too. 
  Otherwise you'll likely corrupt already good tags.
 

well, i have a C skeleton that i could modify, but yours below
looks vastly simpler.  how would i use sed to run this against?


 With 's/\?$/\?php/g' and sufficient quoting,
 maybe removing extra spaces, it should be fine. :-)
 

ha! doubt if i hv any spaces after ?php.  too lazy;)

-g

 
 
 -- 
 Polytropon
 Magdeburg, Germany
 Happy FreeBSD user since 4.0
 Andra moi ennepe, Mousa, ...

-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Gary Kline
On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
 Do you have an error for it?
 
 If not... add after the first ?
 error_reporting(9);
 
 And see what it reports.


There were no errors that should up when i launched this script
on www.thought.org; it simply failed; no output.  ...Another php
script that output a random string on the same page did have
errors.  I thought i would try this simpler script first.  will
add the err line and retry, tx,

gary


 
 --
 Ryan
 PHP dev.
 
 
 On Mar 23, 2011, at 11:45 AM, Gary Kline wrote:
 
  
  Guys,
  
  Can any of you php hackers tell me why this simple self-hacked
  counter bomb?
  
  appended.
  
  tia.
  
  -- 
  Gary Kline  kl...@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
  
  !--
  //
  //  $Id: count.php,v 1.2 2004/01/22 21:58:48 kline Exp kline $
  //
  --!
  
  ?php
  
  $directory=./countdir/;
  
  if (! (file_exists( ($directory.$file)) ))
  {
  if (! ($fp = fopen( ($directory.$file), w)) )
  {
  echo Can't create file '$directory.$file';
  exit(1);
  }
  else
  {
  fseek($fp,0);
  fputs($fp, $count);
  fputs($fp, \n);
  fputs($fp, $file);
  fclose($fp);
  }
  }
  
  if (file_exists( ($directory.$file)))
  {
 $fp = fopen($directory.$file, r+);
 flock($fp, 1);
 $count = fgets($fp, 4096);
 $count += 1;
 fseek($fp,0);
  fputs($fp, $count);
  fputs($fp, \n);
 fputs($fp, $file);
  
 flock($fp, 3);
 fclose($fp);
  ?
  
  CENTER
  FONT COLOR=#66  !---  rich dark bluegrey ---
  FONT SIZE=2
  
  ?
 print  there have been ;
  ?
  
  FONT SIZE=+1
  FONT COLOR=#FF
  
  ?
  print $count;
  ?
  
  /FONT
  /FONT
  ?
  print hits\n;
  ?
  
  /CENTER
  
  ?
  
  } 
  else
  {
 print Can't find file, check '$directory.$file'\n;
  }
  
  ?
  
  ___
  freebsd-questions@freebsd.org mailing list
  http://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
 

-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Ryan Coleman
Check your apache error_log, too.

On Mar 24, 2011, at 12:56 PM, Gary Kline wrote:

 On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
 Do you have an error for it?
 
 If not... add after the first ?
 error_reporting(9);
 
 And see what it reports.
 
 
   There were no errors that should up when i launched this script
   on www.thought.org; it simply failed; no output.  ...Another php
   script that output a random string on the same page did have
   errors.  I thought i would try this simpler script first.  will
   add the err line and retry, tx,
 
   gary
 
 
 
 --
 Ryan
 PHP dev.
 
 
 On Mar 23, 2011, at 11:45 AM, Gary Kline wrote:
 
 
 Guys,
 
 Can any of you php hackers tell me why this simple self-hacked
 counter bomb?
 
 appended.
 
 tia.
 
 -- 
 Gary Kline  kl...@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
 
 !--
 //
 //  $Id: count.php,v 1.2 2004/01/22 21:58:48 kline Exp kline $
 //
 --!
 
 ?php
 
 $directory=./countdir/;
 
 if (! (file_exists( ($directory.$file)) ))
 {
 if (! ($fp = fopen( ($directory.$file), w)) )
 {
 echo Can't create file '$directory.$file';
 exit(1);
 }
 else
 {
 fseek($fp,0);
 fputs($fp, $count);
 fputs($fp, \n);
 fputs($fp, $file);
 fclose($fp);
 }
 }
 
 if (file_exists( ($directory.$file)))
 {
   $fp = fopen($directory.$file, r+);
   flock($fp, 1);
   $count = fgets($fp, 4096);
   $count += 1;
   fseek($fp,0);
 fputs($fp, $count);
 fputs($fp, \n);
   fputs($fp, $file);
 
   flock($fp, 3);
   fclose($fp);
 ?
 
 CENTER
 FONT COLOR=#66  !---  rich dark bluegrey ---
 FONT SIZE=2
 
 ?
   print  there have been ;
 ?
 
 FONT SIZE=+1
 FONT COLOR=#FF
 
 ?
 print $count;
 ?
 
 /FONT
 /FONT
 ?
 print hits\n;
 ?
 
 /CENTER
 
 ?
 
 } 
 else
 {
   print Can't find file, check '$directory.$file'\n;
 }
 
 ?
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
 
 
 -- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Gary Kline
On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
 Do you have an error for it?
 
 If not... add after the first ?
 error_reporting(9);
 
 And see what it reports.
 
 --
 Ryan
 PHP dev.
 

save the bandwidth...


Ok, i added the error_reporting line to both scripts.  No change
from the count.php, and the same output as prev from my script that
tries to pick a random entry from some 70 quotes.  here is what the
randomquote.php scipt output onto the home page:




Last updated:
17 February, 2011

echo err-9 line below:\n; $number-1){ // If ran out of quotes,
start again! $num=0; } if (file_exists($directory.$quotecountfile))
{ $nu = fopen ($directory.$quotecountfile, w); fputs($nu,$num); }
else { die(Cant Find $quotecountfile); } } ?


Note that i added the echo line just now.  

Having a quote isn't as meaningful as giving users the latest
pagecount.  That still fails without any errors.  

gary


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Brad Mettee

Gary Kline wrote:

On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
  

Do you have an error for it?

If not... add after the first ?
error_reporting(9);

And see what it reports.

--
Ryan
PHP dev.




save the bandwidth...


Ok, i added the error_reporting line to both scripts.  No change
from the count.php, and the same output as prev from my script that
tries to pick a random entry from some 70 quotes.  here is what the
randomquote.php scipt output onto the home page:




Last updated:
17 February, 2011

echo err-9 line below:\n; $number-1){ // If ran out of quotes,
start again! $num=0; } if (file_exists($directory.$quotecountfile))
{ $nu = fopen ($directory.$quotecountfile, w); fputs($nu,$num); }
else { die(Cant Find $quotecountfile); } } ?


Note that i added the echo line just now.  


Having a quote isn't as meaningful as giving users the latest
pagecount.  That still fails without any errors.  


gary

It looks like it's not interpreting the php code start somehow.

Can you show the lines immediately above, going up to the Last 
Modified script?


I can also see a ? further down the webpage. It might be a simple 
case of mis-matched start/stop tags.


--
Brad Mettee
PC HotShots, Inc.
Baltimore, MD
(410) 426-7617
- Let us bring out the **Power** of your PCs. -
- Custom Business Software Solutions since 1991 -
Visit us http://www.pchotshots.com for information about our company.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Ryan Coleman
Here's a quick and dirty option...
FIRST make sure your permissions on the folder you want to write the countfile 
to is either at RWX to all or is owned by the Apache run user (PHP by default 
runs under the Apache Service user).

I ran this in file test.php on my server. Give it a whirl.

?
$dir = /path/to/stored/counts/;
$dir = $_SERVER['DOCUMENT_ROOT'].test/; //This was to test in test 
directory in VHOST root folder.
$file = $_SERVER['PHP_SELF']..txt; //this keeps it from being loaded in 
browser as a php-executable
#$file = urlencode($_SERVER['REQUEST_URI'])..txt
//  This option if uncommented will make 
/file/path/filename.php?that=thisfive=5 
//  turn into 
%2Ffile%2Fpath%2Ffilename.php%3Fthat%3Dthis%26five%3D5. Not pretty but 
functional.

if(!is_file($dir.$file)) {
$dump = fopen($dir.$file, x+);
fclose($dump);
}
//Read current value
$fp_read = fopen($dir.$file, r);
$count = fread($fp_read, filesize($dir.$file)+1);
fclose($fp_read);

//Convert count to integer
$new_count = ((int)$count);
//Increase count by 1
$new_count++;


//Reopen to write new value
$fp = fopen($dir.$file, w+);
fwrite($fp, $new_count);
fclose($fp);

echo A count was added. It was #.$new_count;
?

On Mar 24, 2011, at 1:53 PM, Gary Kline wrote:

 On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
 Do you have an error for it?
 
 If not... add after the first ?
 error_reporting(9);
 
 And see what it reports.
 
 --
 Ryan
 PHP dev.
 
 
   save the bandwidth...
 
 
 Ok, i added the error_reporting line to both scripts.  No change
 from the count.php, and the same output as prev from my script that
 tries to pick a random entry from some 70 quotes.  here is what the
 randomquote.php scipt output onto the home page:
 
 
 
 
 Last updated:
 17 February, 2011
 
 echo err-9 line below:\n; $number-1){ // If ran out of quotes,
 start again! $num=0; } if (file_exists($directory.$quotecountfile))
 { $nu = fopen ($directory.$quotecountfile, w); fputs($nu,$num); }
 else { die(Cant Find $quotecountfile); } } ?
 
 
 Note that i added the echo line just now.  
 
 Having a quote isn't as meaningful as giving users the latest
 pagecount.  That still fails without any errors.  
 
 gary
 
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Gary Kline
On Wed, Mar 23, 2011 at 07:11:15PM +0100, Fr?d?ric Perrin wrote:
 Gary Kline kl...@thought.org 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@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Ryan Coleman
 Gary, you missed the put... fput($fp, $file); means you're dropping the 
filename INTO the storage file.


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

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-24 Thread Gary Kline
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 kl...@thought.org 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@freebsd.org mailing list
  http://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to 
  freebsd-questions-unsubscr...@freebsd.org
  
  -- 
  Gary Kline  kl...@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-unsubscr...@freebsd.org
 
 

-- 
 Gary Kline  kl...@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-unsubscr...@freebsd.org


why does this simple counter fail?

2011-03-23 Thread Gary Kline

Guys,

Can any of you php hackers tell me why this simple self-hacked
counter bomb?

appended.

tia.

-- 
 Gary Kline  kl...@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

!--
//
//  $Id: count.php,v 1.2 2004/01/22 21:58:48 kline Exp kline $
//
--!

?php

$directory=./countdir/;

if (! (file_exists( ($directory.$file)) ))
{
if (! ($fp = fopen( ($directory.$file), w)) )
{
echo Can't create file '$directory.$file';
exit(1);
}
else
{
fseek($fp,0);
fputs($fp, $count);
fputs($fp, \n);
fputs($fp, $file);
fclose($fp);
}
}

if (file_exists( ($directory.$file)))
{
$fp = fopen($directory.$file, r+);
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
fputs($fp, $count);
fputs($fp, \n);
fputs($fp, $file);

flock($fp, 3);
fclose($fp);
?

CENTER
FONT COLOR=#66  !---  rich dark bluegrey ---
FONT SIZE=2

?
print  there have been ;
?

FONT SIZE=+1
FONT COLOR=#FF

?
print $count;
?

/FONT
/FONT
?
print hits\n;
?

/CENTER

?

} 
else
{
print Can't find file, check '$directory.$file'\n;
}

?

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-23 Thread Ryan Coleman
Do you have an error for it?

If not... add after the first ?
error_reporting(9);

And see what it reports.

--
Ryan
PHP dev.


On Mar 23, 2011, at 11:45 AM, Gary Kline wrote:

 
   Guys,
 
   Can any of you php hackers tell me why this simple self-hacked
   counter bomb?
 
   appended.
 
   tia.
 
 -- 
 Gary Kline  kl...@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
 
 !--
 //
 //$Id: count.php,v 1.2 2004/01/22 21:58:48 kline Exp kline $
 //
 --!
 
 ?php
 
 $directory=./countdir/;
 
 if (! (file_exists( ($directory.$file)) ))
 {
   if (! ($fp = fopen( ($directory.$file), w)) )
   {
   echo Can't create file '$directory.$file';
   exit(1);
   }
   else
   {
   fseek($fp,0);
   fputs($fp, $count);
   fputs($fp, \n);
   fputs($fp, $file);
   fclose($fp);
   }
 }
 
 if (file_exists( ($directory.$file)))
 {
$fp = fopen($directory.$file, r+);
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
   fputs($fp, $count);
   fputs($fp, \n);
fputs($fp, $file);
 
flock($fp, 3);
fclose($fp);
 ?
 
   CENTER
   FONT COLOR=#66  !---  rich dark bluegrey ---
   FONT SIZE=2
 
 ?
print  there have been ;
 ?
 
   FONT SIZE=+1
   FONT COLOR=#FF
 
 ?
 print $count;
 ?
 
   /FONT
   /FONT
 ?
 print hits\n;
 ?
 
   /CENTER
 
 ?
 
 } 
 else
 {
print Can't find file, check '$directory.$file'\n;
 }
 
 ?
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-23 Thread Ryan Coleman
On a side note, I'd nix $count += 1;
for 
$count++;


--
ryan

On Mar 23, 2011, at 11:45 AM, Gary Kline wrote:

 
   Guys,
 
   Can any of you php hackers tell me why this simple self-hacked
   counter bomb?
 
   appended.
 
   tia.
 
 -- 
 Gary Kline  kl...@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
 
 !--
 //
 //$Id: count.php,v 1.2 2004/01/22 21:58:48 kline Exp kline $
 //
 --!
 
 ?php
 
 $directory=./countdir/;
 
 if (! (file_exists( ($directory.$file)) ))
 {
   if (! ($fp = fopen( ($directory.$file), w)) )
   {
   echo Can't create file '$directory.$file';
   exit(1);
   }
   else
   {
   fseek($fp,0);
   fputs($fp, $count);
   fputs($fp, \n);
   fputs($fp, $file);
   fclose($fp);
   }
 }
 
 if (file_exists( ($directory.$file)))
 {
$fp = fopen($directory.$file, r+);
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
   fputs($fp, $count);
   fputs($fp, \n);
fputs($fp, $file);
 
flock($fp, 3);
fclose($fp);
 ?
 
   CENTER
   FONT COLOR=#66  !---  rich dark bluegrey ---
   FONT SIZE=2
 
 ?
print  there have been ;
 ?
 
   FONT SIZE=+1
   FONT COLOR=#FF
 
 ?
 print $count;
 ?
 
   /FONT
   /FONT
 ?
 print hits\n;
 ?
 
   /CENTER
 
 ?
 
 } 
 else
 {
print Can't find file, check '$directory.$file'\n;
 }
 
 ?
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-23 Thread Paul Macdonald

On 23/03/2011 16:45, Gary Kline wrote:

Guys,

Can any of you php hackers tell me why this simple self-hacked
counter bomb?

appended.

tia.

$file doesn't look to be set anywhere

if its a web script ( as opposed to cmd line cli) tyhen its probably 
passed as a POST or GET variable.,


register_globals needs to be on for this variable to be auto set,

if the form is submitted via POST,  change script to:

$directory=./countdir/;
$file=$_POST['file'];


if the form is submitted via GET (you'd see the file=variable in the address 
bar),  change script to:

$directory=./countdir/;
$file=$_GET['file'];


Of course you want to sanitise this $file variable so that it can't be hacked.



--
-
Paul Macdonald
IFDNRG Ltd
Web and video hosting
-
t: 0131 5548070
m: 07534206249
e: p...@ifdnrg.com
w: http://www.ifdnrg.com
-
IFDNRG
40 Maritime Street
Edinburgh
EH6 6SA
-


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-23 Thread Ryan Coleman


On Mar 23, 2011, at 12:14 PM, Paul Macdonald wrote:

 On 23/03/2011 16:45, Gary Kline wrote:
  Guys,
 
  Can any of you php hackers tell me why this simple self-hacked
  counter bomb?
 
  appended.
 
  tia.
 $file doesn't look to be set anywhere
 
 if its a web script ( as opposed to cmd line cli) tyhen its probably passed 
 as a POST or GET variable.,
 
 register_globals needs to be on for this variable to be auto set,
 
 if the form is submitted via POST,  change script to:
 
 $directory=./countdir/;
 $file=$_POST['file'];
 
 
 if the form is submitted via GET (you'd see the file=variable in the address 
 bar),  change script to:
 
 $directory=./countdir/;
 $file=$_GET['file'];
 
 
 Of course you want to sanitise this $file variable so that it can't be hacked.

Additionally you could do:

$file = $_SERVER['PHP_SELF'];

Which will tie the filename to the actual PHP file.

But you might want to do something like...

$file = urlencode($_SERVER['REQUEST_URI'])..txt;

to make it the full url, safe vars for file names and add .txt to make it 
readable in other things not 
FreeBSD.___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: why does this simple counter fail?

2011-03-23 Thread Frédéric Perrin
Gary Kline kl...@thought.org 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.

-- 
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-unsubscr...@freebsd.org