php-general Digest 26 Mar 2007 11:17:48 -0000 Issue 4698

2007-03-26 Thread php-general-digest-help

php-general Digest 26 Mar 2007 11:17:48 - Issue 4698

Topics (messages 251343 through 251358):

Re: Optimization of all mysql databases on a server
251343 by: Chris
251353 by: Tijnema !

Re: Book Suggestion for ZCE
251344 by: Zoltán Németh

Re: My own captcha from 2 years ago..
251345 by: tedd
251346 by: tedd
251350 by: Jake McHenry
251354 by: Tijnema !

Re: What is wrong with this function please?
251347 by: Zoltán Németh
251348 by: Jake McHenry

Re: Important Design Patterns
251349 by: Travis Doherty

SNMP support on compile from source FastCGI
251351 by: Matt Arnilo S. Baluyos (Mailing Lists)
251352 by: Matt Arnilo S. Baluyos (Mailing Lists)

gethostbyname () uses old DNS server
251355 by: Kent Tong
251356 by: Stut
251357 by: Kent Tong

Perl find and replace in PHP
251358 by: rluckhurst.resmaster.com

Administrivia:

To subscribe to the digest, e-mail:
[EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]

To post to the list, e-mail:
php-general@lists.php.net


--
---BeginMessage---

itoctopus wrote:

The purpose of this script is to optimize all associated tables in all
databases on a mysql server. This script is working great, you can put in a
CRON and run it every day. Feel free to throw in your 2 cents!


It's going to time out if you have any large databases or tables.

Also a much easier option is to run

mysqlcheck -o ...

--
Postgresql  php tutorials
http://www.designmagick.com/
---End Message---
---BeginMessage---

On 3/26/07, Chris [EMAIL PROTECTED] wrote:

itoctopus wrote:
 The purpose of this script is to optimize all associated tables in all
 databases on a mysql server. This script is working great, you can put in a
 CRON and run it every day. Feel free to throw in your 2 cents!

It's going to time out if you have any large databases or tables.


What about set_time_limit(99)??



Also a much easier option is to run

mysqlcheck -o ...


That's true :)

Tijnema


--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---End Message---
---BeginMessage---
2007. 03. 24, szombat keltezéssel 14.00-kor itoctopus ezt írta:
 Sams - Zend Php Certification Study Guide for the certification.
 An excellent book on PHP is PHP5 Power Programming (by Prentice Hall).

also a great book about PHP5 is: Advanced PHP Programming (by George
Schlossnagle)

greets
Zoltán Németh

 
 --
 itoctopus - http://www.itoctopus.com
 Danial Rahmanzadeh [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  hey dudes,
  i want to know that which books are good to read  before ZCE exam.
   I have read php 5 and php 4 study guides and php 4 practice tests. I have
  also read php|architect's guide to php security and bought a 10 slot
 sample
  exam. What else do you suggest?
  cheers,
  Danial
 
 
---End Message---
---BeginMessage---

At 10:49 AM -0400 3/25/07, Jake McHenry wrote:

Do I call the image creation file in an html img tag? I've tried a bunch of
things, and this is the only way I've been able to display the image inline
so far, without the image headers blocking the rest of my output

I've been reading and somewhat interested in the audio and pic captchas..
But audio won't work for my intranet... Hardly any of the sets have
speakers... Productivity solution I guess...


Jake

The audio is for visually impaired and unless their also deaf, they 
have sound turned on.


tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com
---End Message---
---BeginMessage---

At 5:05 PM +0200 3/25/07, Dotan Cohen wrote:

On 25/03/07, tedd [EMAIL PROTECTED] wrote:

What about an audio Captcha?

Your thoughts?

tedd


I do a lot of my browsing at the university library. I can't have any
sound being made there each time I must enter a capcha. Don't use
audio, or provide an alternative.

Dotan Cohen


Dotan:

I understand. There are all sorts of reasons why you want to provide 
more than just one form of captcha IF you're going to use something 
like that (sighted, blind, deaf, deaf-blind, dyslexic, and so on). 
And, there are all sorts of captchas that can be navigated by most.


I was mainly interested in Tijnema's comments regarding sending the 
key for a captcha and how it could be cracked.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com
---End Message---
---BeginMessage---
Like I said... Even if they have sound turned on.. Which all my sets do...
Most of them don't have speakers... That was put into effect over a year ago
due to some people listening to those damn screaming prank things at full
volume... Anyways... I was searching the php site, and it said there used to
be a bug that 

Re: [PHP] Optimization of all mysql databases on a server

2007-03-26 Thread Tijnema !

On 3/26/07, Chris [EMAIL PROTECTED] wrote:

itoctopus wrote:
 The purpose of this script is to optimize all associated tables in all
 databases on a mysql server. This script is working great, you can put in a
 CRON and run it every day. Feel free to throw in your 2 cents!

It's going to time out if you have any large databases or tables.


What about set_time_limit(99)??



Also a much easier option is to run

mysqlcheck -o ...


That's true :)

Tijnema


--
Postgresql  php tutorials
http://www.designmagick.com/

--
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



Re: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Tijnema !

On 3/26/07, Jake McHenry [EMAIL PROTECTED] wrote:

Like I said... Even if they have sound turned on.. Which all my sets do...
Most of them don't have speakers... That was put into effect over a year ago
due to some people listening to those damn screaming prank things at full
volume... Anyways... I was searching the php site, and it said there used to
be a bug that looks somewhat similar to my problem, but it said it was fixed
long ago... Not sure if this is even close to it or not, but this is the
first time I've run into a sessions problem.

Just to simplify...

I have this on index.php

?php
session_start();

$before = $_SESSION['code'];

echo 'img src=image.php';

$after = $_SESSION['code'];

echo $before .' ' . $after;
?

Then in image.php is my captcha... And where the session variable 'code' is
being created and updated...

In image.php is this:

?php
session_start();

..captcha code..
$_SESSION['code'] = rand(blahblahblah) to get the random code
?


When I view index.php, the image displays, with a new code each time...
Working as it should, but the session variable echos out the previously
generated value, instead of the current value to match whats in the
picture... I'm not sure what I've done... But you can see from
http://nittanytravel.com:8080/$before and $after have the same value...

In that bug report I was reading it said that this happened until
session_start was called again.. But it said it was fixed back in php4...

Not sure what I missed :(

Thanks,
Jake


Did you read my previous post?
I explained why this occurs, as it is normal that a script behaves like this.


I believe the way this script behaves is quite normal. Look at the way
the scripts are called. First index.php, then rnum1.php and then
rnum2.php.
First index.php is called and all session variables are posted with
that action. Then rnum1.php is called, and the session variables are
edited. Then rnum2.php is called, session variables are edited again,
but index.php is never called again, and so the session variables are
never send to the script. Until you load the script again.
So if you're implementing this in a POST form, the browser should
submit both POST and the right session variables to your parse script.


Above is what you missed i think ;)



Example code which works :)

index.php:
?php

echo img src='rnum1.php';

echo form action='parse.php' method='post'input name='code'input
type='submit' value='confirm'/form;
?

parse.php:
?php
session_start();
if($_SESSION['security_code'] == $_POST['code']) {
   echo Right code entered.;
} else {
   echo Wrong code entered.;
}
?


Did you test above code? You could use it like that.



This is btw not a very useful CAPTCHA, because it should stop
computers from submitting data, but a little bit smart programmer
knows that he has to get session information from the image, and
submit that to the form. Or what i saw used lately by a cracker, he
was just using his own values in session and post, and so they matched
:)
So you should never send the same code as the code that has to be
entered. Even encrypting with MD5 only won't stop hackers to defeat
your script. Maybe you could use a database with this, so that you
pass a reference to the real number shown. So that you have an ID and
a CODE column. in rnum1.php you store the code into the database, and
get the ID of the last one inserted (A discussion about this was
around this list lately) Then you show the code in an image, and you
store the ID in the session. Then you get ID from the session, then
get the code from the database using the ID and compare it to the one
entered in the form.


This might be of interest, because cracking should be avoided as
CAPTCHA is meant to stop from autosubmitting by computers.

Tijnema







 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED]
 Sent: Sunday, March 25, 2007 7:54 PM
 To: Jake McHenry; 'tedd'; php-general@lists.php.net
 Subject: RE: [PHP] My own captcha from 2 years ago..

 At 10:49 AM -0400 3/25/07, Jake McHenry wrote:
 Do I call the image creation file in an html img tag? I've
 tried a bunch of
 things, and this is the only way I've been able to display
 the image inline
 so far, without the image headers blocking the rest of my output
 
 I've been reading and somewhat interested in the audio and
 pic captchas..
 But audio won't work for my intranet... Hardly any of the sets have
 speakers... Productivity solution I guess...
 
 Jake

 The audio is for visually impaired and unless their also deaf, they
 have sound turned on.

 tedd
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 --
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.446 / Virus Database: 268.18.18/733 - Release
 Date: 3/25/2007 11:07 AM



--
No virus found in this outgoing message.
Checked by 

[PHP] gethostbyname () uses old DNS server

2007-03-26 Thread Kent Tong
Hi,

We have moved our DNS server from one IP to another. But on a Linux
server, the PHP programs keep using the old DNS server IP. For 
example, for a simple php file:

? echo gethostbyname (smtp.cpttm); ?

When it is run, it tries to lookup smtp.cpttm using the old DNS 
server (I know it using tcpdump). The new DNS server is specified in 
/etc/resolv.conf. If I issue ping smtp.cpttm in a command prompt,
then tcpdump shows that it is accessing the new DNS server.

Any idea? Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gethostbyname () uses old DNS server

2007-03-26 Thread Stut

Kent Tong wrote:

We have moved our DNS server from one IP to another. But on a Linux
server, the PHP programs keep using the old DNS server IP. For 
example, for a simple php file:


? echo gethostbyname (smtp.cpttm); ?

When it is run, it tries to lookup smtp.cpttm using the old DNS 
server (I know it using tcpdump). The new DNS server is specified in 
/etc/resolv.conf. If I issue ping smtp.cpttm in a command prompt,

then tcpdump shows that it is accessing the new DNS server.


Assuming you're using a web server it's possible PHP is caching the DNS 
server details. Try restarting the web server. Alternatively try the 
same script on the command line.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: gethostbyname () uses old DNS server

2007-03-26 Thread Kent Tong
Stut stuttle at gmail.com writes:

 Assuming you're using a web server it's possible PHP is caching the DNS 
 server details. Try restarting the web server. Alternatively try the 
 same script on the command line.

Wow! You're right! Stopping apache and then starting it (in two steps) 
solves the problem! In fact, I had tried restarting it 
(/etc/init.d/apache restart) but it didn't make any difference.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Perl find and replace in PHP

2007-03-26 Thread rluckhurst
Hi All

I am porting some perl to PHP and have struck a small snag. The perl
script has quite a few substitutions that take place so data can be fed
into a html page.

The script uses the following perl syntax

$html = `cat search_results.html`;
$html =~ s/%Accom/$accom/g;

As I understand perl that should cat the html file into a variable called
$html. It should then perform a global substitution replacing %Accom with
the contents of the variable $accom.

Is such a thing possible in PHP? If so how? I have been doing google
searches for a while and can find no simple explanation of how to perform
this in PHP. The nearest I can find is using a preg_replace but I am
unsure if that will do what I need.

Does anyone know if this can be done?

Regards

Richard Luckhurst

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Perl find and replace in PHP

2007-03-26 Thread Zoltán Németh
2007. 03. 26, hétfő keltezéssel 21.17-kor [EMAIL PROTECTED] ezt
írta:
 Hi All
 
 I am porting some perl to PHP and have struck a small snag. The perl
 script has quite a few substitutions that take place so data can be fed
 into a html page.
 
 The script uses the following perl syntax
 
 $html = `cat search_results.html`;
 $html =~ s/%Accom/$accom/g;
 
 As I understand perl that should cat the html file into a variable called
 $html. It should then perform a global substitution replacing %Accom with
 the contents of the variable $accom.
 
 Is such a thing possible in PHP? If so how? I have been doing google
 searches for a while and can find no simple explanation of how to perform
 this in PHP. The nearest I can find is using a preg_replace but I am
 unsure if that will do what I need.
 
 Does anyone know if this can be done?

$html = str_replace($search, $replace, file_get_contents($filename));

or you could use preg_replace if you want to search and replace based on
regular expressions
see:

http://hu2.php.net/manual/en/function.file-get-contents.php
http://hu2.php.net/manual/en/function.str-replace.php
http://hu2.php.net/manual/en/function.preg-replace.php

greets
Zoltán Németh

 
 Regards
 
 Richard Luckhurst
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Newline and tab characters

2007-03-26 Thread Arno Kuhl
I've just noticed that \r\n and \t characters create a space when
rendered in the browser (tested in IE and Firefox). I'd always thought the
browser would ignore these characters. This wouldn't normally be a problem
but the wysiwyg html editor in the cms I'm using tries to be friendly by
formatting the html code, so something like

span style=\COLOR: #af0e14\get/spanspan style=\COLOR:
#33\online/span

becomes

\r\n\t\tspan style=\COLOR: #af0e14\get/span\r\n\t\tspan
style=\COLOR: #33\online/span

and instead of being displayed as getonline it's displayed as get online.

Is there a simple way to sort this out or do I need to create a function to
strip these characters before display, checking first that they don't occur
within a pre tag in which case I mustn't strip them.

TIA
Arno

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newline and tab characters

2007-03-26 Thread Zoltán Németh
2007. 03. 26, hétfő keltezéssel 13.54-kor Arno Kuhl ezt írta:
 I've just noticed that \r\n and \t characters create a space when
 rendered in the browser (tested in IE and Firefox). I'd always thought the
 browser would ignore these characters. This wouldn't normally be a problem
 but the wysiwyg html editor in the cms I'm using tries to be friendly by
 formatting the html code, so something like
 
 span style=\COLOR: #af0e14\get/spanspan style=\COLOR:
 #33\online/span
 
 becomes
 
 \r\n\t\tspan style=\COLOR: #af0e14\get/span\r\n\t\tspan
 style=\COLOR: #33\online/span
 
 and instead of being displayed as getonline it's displayed as get online.
 
 Is there a simple way to sort this out or do I need to create a function to
 strip these characters before display, checking first that they don't occur
 within a pre tag in which case I mustn't strip them.

why not strip them before storing the html content into the DB?
that way you need to strip them only once, while if you strip them on
display you need to strip them once for each request.
and you don't need checking with pre tags and stuff.
just do a 
str_replace(array(\n, \r, \t), , $text);
on it and that's all

greets
Zoltán Németh

 
 TIA
 Arno
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newline and tab characters

2007-03-26 Thread Zoltán Németh
2007. 03. 26, hétfő keltezéssel 13.58-kor Zoltán Németh ezt írta:
 2007. 03. 26, hétfő keltezéssel 13.54-kor Arno Kuhl ezt írta:
  I've just noticed that \r\n and \t characters create a space when
  rendered in the browser (tested in IE and Firefox). I'd always thought the
  browser would ignore these characters. This wouldn't normally be a problem
  but the wysiwyg html editor in the cms I'm using tries to be friendly by
  formatting the html code, so something like
  
  span style=\COLOR: #af0e14\get/spanspan style=\COLOR:
  #33\online/span
  
  becomes
  
  \r\n\t\tspan style=\COLOR: #af0e14\get/span\r\n\t\tspan
  style=\COLOR: #33\online/span
  
  and instead of being displayed as getonline it's displayed as get online.
  
  Is there a simple way to sort this out or do I need to create a function to
  strip these characters before display, checking first that they don't occur
  within a pre tag in which case I mustn't strip them.
 
 why not strip them before storing the html content into the DB?
 that way you need to strip them only once, while if you strip them on
 display you need to strip them once for each request.
 and you don't need checking with pre tags and stuff.
 just do a 
 str_replace(array(\n, \r, \t), , $text);
 on it and that's all

err, sorry I misunderstood your sentence about the pre tags...
yeah, you should somehow avoid replacing within pre tags. maybe in
first step find all pre tags, save their contents in an array, then do
the str_replace, and after that restore the pre tags contents with
preg_replace

greets
Zoltán Németh

 
 greets
 Zoltán Németh
 
  
  TIA
  Arno
  
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread tedd

At 10:02 PM -0400 3/25/07, Jake McHenry wrote:

Like I said... Even if they have sound turned on.. Which all my sets do...
Most of them don't have speakers... That was put into effect over a year ago
due to some people listening to those damn screaming prank things at full
volume... Anyways... I was searching the php site, and it said there used to
be a bug that looks somewhat similar to my problem, but it said it was fixed
long ago... Not sure if this is even close to it or not, but this is the
first time I've run into a sessions problem.

Just to simplify...

I have this on index.php

?php
session_start();

$before = $_SESSION['code'];

echo 'img src=image.php';

$after = $_SESSION['code'];

echo $before .' ' . $after;
?

Then in image.php is my captcha... And where the session variable 'code' is
being created and updated...

In image.php is this:

?php
session_start();

..captcha code..
$_SESSION['code'] = rand(blahblahblah) to get the random code
?


When I view index.php, the image displays, with a new code each time...
Working as it should, but the session variable echos out the previously
generated value, instead of the current value to match whats in the
picture... I'm not sure what I've done... But you can see from
http://nittanytravel.com:8080/$before and $after have the same value...

In that bug report I was reading it said that this happened until
session_start was called again.. But it said it was fixed back in php4...

Not sure what I missed :(

Thanks,
Jake



Jake:

Clearly, your image.php is not changing the code (key).

Your blahblahblah has to be less than 32768 if you're running 
windows -- maybe that's the problem. But, I would look to my rand() 
for an answer.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: OT: firstname-lastname fun - SOLVED :) (was: Re: [PHP] preview string with strlen PHP (help))

2007-03-26 Thread tedd

At 12:29 AM +0200 3/26/07, Zoltán Németh wrote:

2007. 03. 23, péntek keltezéssel 20.36-kor Tijnema ! ezt írta:

 On 3/23/07, Németh Zoltán [EMAIL PROTECTED] wrote:
  2007. 03. 23, péntek keltezéssel 17.30-kor Dwayne Heronimo ezt írta:
   YES this works thank nemeth:
 
  your welcome but please call me Zoltán ;)
  (my first name is Zoltán. in Hungary we write names the opposite order
  than anywhere else ;) so that's why my mailbox is set to display 'Németh
  Zoltán' but I sign my mails as 'Zoltán Németh' showing that my first
  name is Zoltán and last name is Németh :) )
 
  greets
  Zoltán Németh

 Ever thought of reversing it in your mailbox?


okay you win :)
I realized that the reverse order probably won't disturb or confuse
anyone in Hungary as they will know that Zoltán is a first name and
Németh is a family name - so I reversed it now

greets
Zoltán Németh


Hey Németh:

Good ! ;-)

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Jochem Maas
Jake McHenry wrote:
 Like I said... Even if they have sound turned on.. Which all my sets do...
 Most of them don't have speakers... That was put into effect over a year ago
 due to some people listening to those damn screaming prank things at full
 volume...

and didn'tr we all have a fun with those :-/

 Anyways... 

indeed ...

 I was searching the php site, and it said there used to
 be a bug that looks somewhat similar to my problem, but it said it was fixed
 long ago... Not sure if this is even close to it or not, but this is the
 first time I've run into a sessions problem.

you don't have a session problem and your not looking at a bug either.
you have a PEBKAC/logic problem with regard to storage/retrieval of the
security code.

 
 Just to simplify...
 
 I have this on index.php
 
 ?php
 session_start();
 
 $before = $_SESSION['code'];
 
 echo 'img src=image.php';
 
 $after = $_SESSION['code'];
 
 echo $before .' ' . $after;
 ?

$before and $after are always going to be the same because image.php
is not being run in the line echo 'img src=image.php';

imagine 3 files and note that in this psuedo solution the
image is *not* generated in the file that outputs it but rather in the file
that outputs and processes the form:

seccode.inc.php -- some security code functions
secform.php -- output the form and processes it's own 'POST'
secimage.php-- outputs the relevant/current 'security image' for 
secform.php

the psuedo contents of these 2 files should be something *like* this:

seccode.inc.php
-- 8 --
?php

function genSecCodeInfo()
{
// generate a random wotsit
$code = rand();

$imgloc = /path/to/sec/images/{$code}.jpg;
/* create an image! */  
/* save the image to $imgloc */

$_SESSION['seccodeinfo'] = array(
'code'  = $code,
'imgloc'= $imgloc,
);
}

function getCurSecCodeInfo()
{
if (isset($_SESSION['seccodeinfo']))
return $_SESSION['seccodeinfo'];

return null;
}


secform.php
-- 8 --
?php

session_start();


if (!empty($_POST)  ($info = getCurSecCodeInfo())) {
if ($_POST['seccode'] == $info['code']) {
echo 'good dog!';
exit;
} else {
echo 'try again mutt.';
}
}

// create/refresh the security code info  image
genSecCodeInfo();

echo '
form action= method=post
image src=/secimage.php alt=you are blind and we didn't bother to 
make this accessible /
input type=text name=seccode /
input type=submit name=submit value=GO /
/form
';


secimage.php
-- 8 --
?php

session_start();

if ($info = getCurSecCodeInfo()) {
/* output all the required headers, etc */
readfile($info['imgloc']);
} else {
// there is no spoon (I mean image)
// so an error image or something
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Newline and tab characters

2007-03-26 Thread Al

Browsers ignore \n \r and \t.  Look at the resultant html source code in your 
browser.

Something is converting them BEFORE sending the html code to the client browser.

Arno Kuhl wrote:

I've just noticed that \r\n and \t characters create a space when
rendered in the browser (tested in IE and Firefox). I'd always thought the
browser would ignore these characters. This wouldn't normally be a problem
but the wysiwyg html editor in the cms I'm using tries to be friendly by
formatting the html code, so something like

span style=\COLOR: #af0e14\get/spanspan style=\COLOR:
#33\online/span

becomes

\r\n\t\tspan style=\COLOR: #af0e14\get/span\r\n\t\tspan
style=\COLOR: #33\online/span

and instead of being displayed as getonline it's displayed as get online.

Is there a simple way to sort this out or do I need to create a function to
strip these characters before display, checking first that they don't occur
within a pre tag in which case I mustn't strip them.

TIA
Arno


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Jake McHenry
 

 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED] 
 Sent: Monday, March 26, 2007 8:49 AM
 To: php-general@lists.php.net
 Subject: RE: [PHP] My own captcha from 2 years ago..
 
 At 10:02 PM -0400 3/25/07, Jake McHenry wrote:
 Like I said... Even if they have sound turned on.. Which all 
 my sets do...
 Most of them don't have speakers... That was put into effect 
 over a year ago
 due to some people listening to those damn screaming prank 
 things at full
 volume... Anyways... I was searching the php site, and it 
 said there used to
 be a bug that looks somewhat similar to my problem, but it 
 said it was fixed
 long ago... Not sure if this is even close to it or not, but 
 this is the
 first time I've run into a sessions problem.
 
 Just to simplify...
 
 I have this on index.php
 
 ?php
 session_start();
 
 $before = $_SESSION['code'];
 
 echo 'img src=image.php';
 
 $after = $_SESSION['code'];
 
 echo $before .' ' . $after;
 ?
 
 Then in image.php is my captcha... And where the session 
 variable 'code' is
 being created and updated...
 
 In image.php is this:
 
 ?php
 session_start();
 
 ..captcha code..
 $_SESSION['code'] = rand(blahblahblah) to get the random code
 ?
 
 
 When I view index.php, the image displays, with a new code 
 each time...
 Working as it should, but the session variable echos out the 
 previously
 generated value, instead of the current value to match whats in the
 picture... I'm not sure what I've done... But you can see from
 http://nittanytravel.com:8080/$before and $after have 
 the same value...
 
 In that bug report I was reading it said that this happened until
 session_start was called again.. But it said it was fixed 
 back in php4...
 
 Not sure what I missed :(
 
 Thanks,
 Jake
 
 
 Jake:
 
 Clearly, your image.php is not changing the code (key).

What would be this clear image you see? It does change the code, otherwise
it would show the same code in the image.. Which it doesn't... And the
session variable wouldn't have anything in it.. Which it does

Not on windows..

Using mt_rand for the numbers, but that's working fine, if I comment out the
image headers and run the file directly echoing out the session, it works
fine, its only when I call it from another file in the img tag...?

Thanks,
Jake



 
 Your blahblahblah has to be less than 32768 if you're running 
 windows -- maybe that's the problem. But, I would look to my rand() 
 for an answer.
 
 Cheers,
 
 tedd
 -- 
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.446 / Virus Database: 268.18.18/733 - Release 
 Date: 3/25/2007 11:07 AM
  
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.18/733 - Release Date: 3/25/2007
11:07 AM
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Brad Fuller
  -Original Message-
  From: tedd [mailto:[EMAIL PROTECTED]
  Sent: Monday, March 26, 2007 8:49 AM
  To: php-general@lists.php.net
  Subject: RE: [PHP] My own captcha from 2 years ago..
 
  At 10:02 PM -0400 3/25/07, Jake McHenry wrote:
  Like I said... Even if they have sound turned on.. Which all
  my sets do...
  Most of them don't have speakers... That was put into effect
  over a year ago
  due to some people listening to those damn screaming prank
  things at full
  volume... Anyways... I was searching the php site, and it
  said there used to
  be a bug that looks somewhat similar to my problem, but it
  said it was fixed
  long ago... Not sure if this is even close to it or not, but
  this is the
  first time I've run into a sessions problem.
  
  Just to simplify...
  
  I have this on index.php
  
  ?php
  session_start();
  
  $before = $_SESSION['code'];
  
  echo 'img src=image.php';
  
  $after = $_SESSION['code'];
  
  echo $before .' ' . $after;
  ?
  
  Then in image.php is my captcha... And where the session
  variable 'code' is
  being created and updated...
  
  In image.php is this:
  
  ?php
  session_start();
  
  ..captcha code..
  $_SESSION['code'] = rand(blahblahblah) to get the random code
  ?
  
  
  When I view index.php, the image displays, with a new code
  each time...
  Working as it should, but the session variable echos out the
  previously
  generated value, instead of the current value to match whats in the
  picture... I'm not sure what I've done... But you can see from
  http://nittanytravel.com:8080/$before and $after have
  the same value...
  
  In that bug report I was reading it said that this happened until
  session_start was called again.. But it said it was fixed
  back in php4...
  
  Not sure what I missed :(
  
  Thanks,
  Jake
  
 
  Jake:
 
  Clearly, your image.php is not changing the code (key).
 
 What would be this clear image you see? It does change the code, otherwise
 it would show the same code in the image.. Which it doesn't... And the
 session variable wouldn't have anything in it.. Which it does
 
 Not on windows..
 
 Using mt_rand for the numbers, but that's working fine, if I comment out
 the
 image headers and run the file directly echoing out the session, it works
 fine, its only when I call it from another file in the img tag...?
 
 Thanks,
 Jake
 
 
 
 
  Your blahblahblah has to be less than 32768 if you're running
  windows -- maybe that's the problem. But, I would look to my rand()
  for an answer.
 
  Cheers,
 
  tedd
  --
  ---
  http://sperling.com  http://ancientstones.com  http://earthstones.com


echo 'img src=image.php';

This does not run or call image.php.

This line of code sends this output to the browser.

The image will not be displayed and the request to change the session
variable will not be made until the browser renders the page.  The browser
will not render the page until PHP has finished parsing the code and sending
the output buffer to the browser.

So any session variables set or changed inside image.php will not show up
until the next request.

This reminds me of an employee that we used to have; she would send me an
e-mail, then run over into my office and say Hey did you get my e-mail?
I'd say No, how long ago did you send it? ... Just now. ... (sigh)

If you want to make sure that the session var is actually being changed in
the script, create another page that the form with the image submits to, and
echo the session var on THAT page.

Also I would like to clarify what someone had posted in a previous message:

Quote:
This is btw not a very useful CAPTCHA, because it should stop
computers from submitting data, but a little bit smart programmer
knows that he has to get session information from the image, and
submit that to the form. Or what i saw used lately by a cracker, he was
just using his own values in session and post, and so they  matched

The above statement is incorrect, assuming that you are using session
cookies to store the user's session ID and nothing else (default setting)

The only thing stored in the user's cookie is the session ID which
corresponds to the session ID on the server.  The server stores the session
data in the /tmp directory and there is no way under this configuration for
the user to spoof any session data except the session ID.  This is why
CAPTCHA images are so effective.

The above quote would be true if the developer used COOKIES to store the
CAPTCHA security code, then it would be very simple to crack ;)

Cheers,

-B

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] syntax question

2007-03-26 Thread Ross
Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES 
('$_POST['cat_name']); 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] syntax question

2007-03-26 Thread cajbecu
Ross wrote:
 Can I put post values directly into insert statements?
 
 $query = INSERT INTO categories (category_name) VALUES 
 ('$_POST['cat_name']); 
 

Yes you can, but it is not secure to do that!

use (insecure):

$query = INSERT INTO categories (category_name) VALUES
('{$_POST['cat_name']}');

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: syntax question

2007-03-26 Thread Ross
thanks.

Ross [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Can I put post values directly into insert statements?

 $query = INSERT INTO categories (category_name) VALUES 
 ('$_POST['cat_name']); 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] combine empty and trim

2007-03-26 Thread Ross
I want to trim any whitepace and check if it is empty in the same  line this 
is not working.

if (empty(trim($_POST['_createcategory']))) { 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine empty and trim

2007-03-26 Thread Brad Bonkoski

Ross wrote:
I want to trim any whitepace and check if it is empty in the same  line this 
is not working.


if (empty(trim($_POST['_createcategory']))) { 

  

perhaps try:
if( strlen(trim($_POST['...']))) = 0 ) { ... }

don't think empty is the right function for this...

-Brad

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine empty and trim

2007-03-26 Thread Stut

Ross wrote:
I want to trim any whitepace and check if it is empty in the same  line this 
is not working.


if (empty(trim($_POST['_createcategory']))) { 


You can't do this because empty needs the variable - it can't work on 
teh return value. The closest you can get would be...


if (isset($_POST['_createcategory']) and
strlen(trim($_POST['_createcategory']))  0) {

Not as neat, but it does the job.

You could also do something like this...

$_POST['_createcategory'] =
isset($_POST['_createcategory']) ?
trim($_POST['_createcategory']) : '';

if (empty($_POST['_createcategory'])) {

Still not pretty but slightly better in that you can cleanse your data 
before you hit logic.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine empty and trim

2007-03-26 Thread Brad Bonkoski

Brad Bonkoski wrote:

Ross wrote:
I want to trim any whitepace and check if it is empty in the same  
line this is not working.


if (empty(trim($_POST['_createcategory']))) {
  

perhaps try:
if( strlen(trim($_POST['...']))) = 0 ) { ... }

don't think empty is the right function for this...

-Brad


opps..  to many ')'
as a follow up read: http://us3.php.net/empty
on empty..

especially the note:
*Note: * *empty()* only checks variables as anything else will result in 
a parse error. In other words, the following will not work: 
*empty(trim($name))*.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: combine empty and trim

2007-03-26 Thread Tim

Ross schrieb:
I want to trim any whitepace and check if it is empty in the same  line this 
is not working.


if (empty(trim($_POST['_createcategory']))) { 

Hi,

try this:

if (isset($_POST['_createcategory']))
{
  $value = trim($_POST['_createcategory']);
  if (empty($value))
  {

  }
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: combine empty and trim

2007-03-26 Thread Colin Guthrie
Stut wrote:
 You could also do something like this...
 
 $_POST['_createcategory'] =
 isset($_POST['_createcategory']) ?
 trim($_POST['_createcategory']) : '';
 
 if (empty($_POST['_createcategory'])) {
 
 Still not pretty but slightly better in that you can cleanse your data
 before you hit logic.

While I too personally do something similar, I should point out that
this is one of the things PHP can be configured (with a patch) to
disallow for security purposes - e.g. do not fiddle with $_* vars
But like I say, I too am guilty as charged here :p

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] syntax question

2007-03-26 Thread Brad Bonkoski

Ross wrote:

Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES 
('$_POST['cat_name']); 

  

Yes, although this is not recommended.
What is someone puts a single quote in there?  Or some other bad 
characters


otherwise... 2 options:

$query = INSERT INTO categories (category_name) VALUES 
('.$_POST['cat_name'].');

-or-
$query = INSERT INTO categories (category_name) VALUES 
('{$_POST['cat_name']}');


-Brad 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine empty and trim

2007-03-26 Thread Robert Cummings
On Mon, 2007-03-26 at 16:23 +0100, Stut wrote:
 Ross wrote:
  I want to trim any whitepace and check if it is empty in the same  line 
  this 
  is not working.
  
  if (empty(trim($_POST['_createcategory']))) { 
 
 You can't do this because empty needs the variable - it can't work on 
 teh return value. The closest you can get would be...
 
 if (isset($_POST['_createcategory']) and
  strlen(trim($_POST['_createcategory']))  0) {
 
 Not as neat, but it does the job.
 
 You could also do something like this...
 
 $_POST['_createcategory'] =
  isset($_POST['_createcategory']) ?
  trim($_POST['_createcategory']) : '';
 
 if (empty($_POST['_createcategory'])) {
 
 Still not pretty but slightly better in that you can cleanse your data 
 before you hit logic.

?php

if( !isset( $_POST['_createcategory'] )
||
empty( ($_POST['_createcategory'] =
trim( $_POST['_createcategory'] )) )
{
// Stuff to do.
}

?

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: combine empty and trim

2007-03-26 Thread Richard Davey

Tim wrote:


Ross schrieb:
I want to trim any whitepace and check if it is empty in the same  
line this is not working.


if (empty(trim($_POST['_createcategory']))) { 

Hi,

try this:

if (isset($_POST['_createcategory']))
{
  $value = trim($_POST['_createcategory']);
  if (empty($value))
  {


Be very careful with empty(). It doesn't do exactly what it says on the 
tin. For example if your _createcategory POST value contained a zero, 
the empty() check will fail in the above instance, giving a false result.


Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: combine empty and trim

2007-03-26 Thread Tim

Richard Davey schrieb:

Tim wrote:


Ross schrieb:
I want to trim any whitepace and check if it is empty in the same  
line this is not working.


if (empty(trim($_POST['_createcategory']))) { 

Hi,

try this:

if (isset($_POST['_createcategory']))
{
  $value = trim($_POST['_createcategory']);
  if (empty($value))
  {


Be very careful with empty(). It doesn't do exactly what it says on the 
tin. For example if your _createcategory POST value contained a zero, 
the empty() check will fail in the above instance, giving a false result.


Cheers,

Rich

You're right.
This function is a good workaround:

//taken from http://php.net/empty
//24-Mar-2007 02:32
function is_empty($var)
{
  return (((is_null($var) || rtrim($var) == '')  $var !== false) || 
(is_array($var)  empty($var)));

}

Best regards
Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Rewriting urls

2007-03-26 Thread lists

Hi,

I am having some problems getting my mod_rewrite to work on my development
server. On my
production server (linux) this works fine. But on my development server it
woun't work.

I have a file basicpage.php that is located in the webroot. I then have
a .htaccess file
with the following content:


#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/

IfModule mod_rewrite.c
 RewriteEngine On
 RewriteRule ^article/([0-9]+)/[-a-zA-Z]+$ /basicpage.php?id=$1
/IfModule


The rewrite works as expected on the production server, but on the development
server it
don't want to work. I also tried it on a windows machine but it don't want to
work there
either.

Any suggestions/insights?

/Peter

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Debugging includes

2007-03-26 Thread Jonathan Kahan

Hi all,

I am attmepting to run a php scrip and this is the error i keep on getting. 
The scripts first 4 lines are below the errors. When errors are returned, 
does that mean that the error is local or in one of the include scripts? I 
have tried to reverse the order of the includes but when i do this the 
errors still are the same it seems. Any help would be greatly appreciated.


Thanks.

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 3


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 4


Parse error: parse error, unexpected T_STRING in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 4


This is the beginning of the file 
C:\WebSites\www\springsystems\Portal\processfiles.inc: .


?
include (./ASN_DBUtilities.php);
include (./PO_Utilities.php);
include (inc_FileManager.php);
include (./ASN_FileManager.php);

Kind Regards
Jonathan Kahan


Systems Developer
Estrin Technologies, inc.
1375 Broadway, 3rd Floor, New York, NY, 10018

Email: [EMAIL PROTECTED]
Web: http://www.estrintech.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Rewriting urls

2007-03-26 Thread Erik Jones

On Mar 26, 2007, at 12:14 PM, [EMAIL PROTECTED] wrote:


Hi,

I am having some problems getting my mod_rewrite to work on my  
development

server. On my
production server (linux) this works fine. But on my development  
server it

woun't work.

I have a file basicpage.php that is located in the webroot. I then  
have

a .htaccess file
with the following content:


#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/

IfModule mod_rewrite.c
 RewriteEngine On
 RewriteRule ^article/([0-9]+)/[-a-zA-Z]+$ /basicpage.php?id=$1
/IfModule


The rewrite works as expected on the production server, but on the  
development

server it
don't want to work. I also tried it on a windows machine but it  
don't want to

work there
either.

Any suggestions/insights?


Yep, take this to the mod_rewrite forums @ http://www.modrewrite.com/  
as this is a php list :)


erik jones [EMAIL PROTECTED]
software developer
615-296-0838
emma(r)





Re: [PHP] Debugging includes

2007-03-26 Thread Richard Davey

Jonathan Kahan wrote:

I am attmepting to run a php scrip and this is the error i keep on 
getting. The scripts first 4 lines are below the errors. When errors are 
returned, does that mean that the error is local or in one of the 
include scripts? I have tried to reverse the order of the includes but 
when i do this the errors still are the same it seems. Any help would be 
greatly appreciated.


Thanks.

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 3


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 4


Parse error: parse error, unexpected T_STRING in 
C:\WebSites\www\springsystems\Portal\processfiles.inc on line 4


This is the beginning of the file 
C:\WebSites\www\springsystems\Portal\processfiles.inc: .


?
include (./ASN_DBUtilities.php);
include (./PO_Utilities.php);
include (inc_FileManager.php);
include (./ASN_FileManager.php);


One of the included files is screwing up. Perhaps it has a syntax error 
in it, or a non-closed PHP tag. The errors are then cascading down 
through the rest of your scripts.


Also check you are allowed to use 'short tags' (? instead of ?php) by 
looking at your phpinfo() dump, because if not then the above will try 
and be parsed as XML, which you really don't want. As you're getting a 
parser error though, my money is on one of the includes being foobared.


If you have access to command-line PHP, try doing:

php -l ASN_DBUtilities.php

etc for each file, to see if there are any immediate parser errors.

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread tedd

At 10:59 AM -0400 3/26/07, Brad Fuller wrote:


echo 'img src=image.php';

This does not run or call image.php.

This line of code sends this output to the browser.


Brad:

Yes, but the browser runs the code by trying to load an image.

Check this out:

http://sperling.com/examples/assorted-captcha/index.php

The first Captcha is the typical type and the image shown is created 
by captcha.php via a simple img tag:


img src=captcha.php

In this example, the key for this is passed via sessions and is not 
included in a cookie nor dependant upon the value of the session id.


Refresh the page and new values are shown because it's the tag that 
causes the captcha.php script to run.


Don't mind the Audio Captcha there, I have a better one.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] syntax question

2007-03-26 Thread tedd

At 3:59 PM +0100 3/26/07, Ross wrote:

Can I put post values directly into insert statements?

$query = INSERT INTO categories (category_name) VALUES
('$_POST['cat_name']);



Open to sql injection.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Brad Fuller
 From: tedd [mailto:[EMAIL PROTECTED]
 At 10:59 AM -0400 3/26/07, Brad Fuller wrote:
 
 echo 'img src=image.php';
 
 This does not run or call image.php.
 
 This line of code sends this output to the browser.
 
 Brad:
 
 Yes, but the browser runs the code by trying to load an image.


... 

My response was attempting to explain why this:

[snip]

session_start();
$before = $_SESSION['code'];
echo 'img src=image.php';
$after = $_SESSION['code'];
echo $before .' ' . $after;

[/snip]

prints the same security code twice.

If it was an include or RPC or cURL, it would be a different story. But the
client (browser) has to request the image for the security code to be
updated in the session.

The php code assigns the value to the $after variable before said request
can occur.  Therefore it makes sense that the same code appears twice.  Once
the browser has fully loaded the page that calls the image, the session
variable has been changed.  But that doesn't happen until all the php code
has been run!!!  Hope that makes sense.

:)



 Check this out:
 
 http://sperling.com/examples/assorted-captcha/index.php
 
 The first Captcha is the typical type and the image shown is created
 by captcha.php via a simple img tag:
 
 img src=captcha.php
 
 In this example, the key for this is passed via sessions and is not
 included in a cookie nor dependant upon the value of the session id.
 
 Refresh the page and new values are shown because it's the tag that
 causes the captcha.php script to run.
 
 Don't mind the Audio Captcha there, I have a better one.
 
 Cheers,
 
 tedd
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 
 --
 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



[PHP] converting video formats

2007-03-26 Thread Bruce Gilbert

Can someoune point me in the right direction as to how (if possible)
to convert a video format uploaded to a server to a flash format
(.flv) no matter what the orginal format is?

thanks

--
::Bruce::

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Rewriting urls

2007-03-26 Thread Peter Lauri
On Monday 26 March 2007 19:49:48 Erik Jones wrote:
 Yep, take this to the mod_rewrite forums @ http://www.modrewrite.com/  
 as this is a php list :)

Thanks. This solved it for me:

http://forum.modrewrite.com/viewtopic.php?p=10796#10796

/Peter

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] converting video formats

2007-03-26 Thread Tijnema !

On 3/26/07, Bruce Gilbert [EMAIL PROTECTED] wrote:

Can someoune point me in the right direction as to how (if possible)
to convert a video format uploaded to a server to a flash format
(.flv) no matter what the orginal format is?

thanks

--
::Bruce::


We had a discussion about having video support in PHP lately on the
PHP internals, but this is yet not directly implemented in PHP. You
should use an external program, and then execute it witth the exec()
function for example.

I can't give you the name of a program, because you don't even tell if
you're using windows/linux. But i think you can find one yourself :)

Tijnema


--
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



Re: [PHP] Rewriting urls

2007-03-26 Thread Erik Jones


On Mar 26, 2007, at 1:18 PM, Peter Lauri wrote:


On Monday 26 March 2007 19:49:48 Erik Jones wrote:

Yep, take this to the mod_rewrite forums @ http://www.modrewrite.com/
as this is a php list :)


Thanks. This solved it for me:

http://forum.modrewrite.com/viewtopic.php?p=10796#10796

/Peter


Glad I could be of indirect help :)

erik jones [EMAIL PROTECTED]
software developer
615-296-0838
emma(r)





Re: [PHP] converting video formats

2007-03-26 Thread Richard Davey

Bruce Gilbert wrote:


Can someoune point me in the right direction as to how (if possible)
to convert a video format uploaded to a server to a flash format
(.flv) no matter what the orginal format is?


We've had good success with automating Sorenson Squeeze directly via 
batched jobs on the server. Video encoding is an expensive process 
(cpu/memory expensive) so best done by dedicated boxes, or on low-freq 
sites at dedicated times of the day.


Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Debugging includes

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 11:31 am, Jonathan Kahan wrote:
 I am attmepting to run a php scrip and this is the error i keep on
 getting.
 The scripts first 4 lines are below the errors. When errors are
 returned,
 does that mean that the error is local or in one of the include
 scripts? I
 have tried to reverse the order of the includes but when i do this the
 errors still are the same it seems. Any help would be greatly
 appreciated.

 Thanks.

 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
 C:\WebSites\www\springsystems\Portal\processfiles.inc on line 3

The error is in this file at this line: ^

It's possible you have MagicQuotes ON and the script exepcts them to
be OFF

There are zillion other possibilities, too, but that one springs to
mind as the most likely.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine empty and trim

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 10:17 am, Ross wrote:
 I want to trim any whitepace and check if it is empty in the same
 line this
 is not working.

 if (empty(trim($_POST['_createcategory']))) {

Define not working if you would...

Personally, I always use isset() to determine if any POST data was
sent, and then deal with what was sent, perhaps doing trim, and always
scrubbing and validating the data.

empty() changed its behaviour on 0 from version to version.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] syntax question

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 9:59 am, Ross wrote:
 Can I put post values directly into insert statements?

 $query = INSERT INTO categories (category_name) VALUES
 ('$_POST['cat_name']);

Sure!

If you want your webserver to get hacked by the Bad Guys, just go
right ahead and do that.

[that was tounge-in-cheek]

Start reading here:
http://phpsec.org

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: syntax question

2007-03-26 Thread Richard Lynch
None of the previous posts added any security...

They all ONLY provided different syntax to leave your database wide
open for abuse.

This is much safer:
$cat_name_sql = myqsl_real_escape_string($_POST['cat_name']);
$query = insert into categories (category_name) values
('$cat_name_sql');

You could/should also check for what you consider valid characters in
a 'cat_name'

if (!preg_match(|^[a-z0-9_ -]+$|i', $_POST['cat_name'])){
  //tell the user their cat_name is invalid, and don't do the INSERT
}

On Mon, March 26, 2007 10:14 am, Ross wrote:
 thanks.

 Ross [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Can I put post values directly into insert statements?

 $query = INSERT INTO categories (category_name) VALUES
 ('$_POST['cat_name']);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add New Records Only!

2007-03-26 Thread Rahul Sitaram Johari
Ave,

 Another option would be to just create a UNIQUE INDEX on the fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.

Could you possibly elaborate on this?
Things I'm trying are still not working out the way or want to, or
efficiently. So still looking for a solution.

Thanks.


On 3/23/07 8:01 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 If the table is small, you could maybe do:
 
 delete from foo where id in (select b.id from foo as a, foo as b where
 a.id  b.id and a.field1 = b.field1 and a.field2 = b.field2 and ...)
 
 Another option would be to just create a UNIQUE INDEX on the fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.
 
 On Fri, March 23, 2007 11:51 am, Satyam wrote:
 Delete from table where id = (select min(id) from table group by
 field1,
 field2 ,...  having count(id)  1)
 
 Id is the unique primary key, fieldn are the fields that can be
 duplicated.
 Each time this runs it will remove one occurence of the all duplicated
 records.  You'd have to run it several times until it deletes no more
 records.   In MySql, you cannot have the same table in the 'delete'
 and in
 the subquery, thus, you will have to first insert the id's in an
 auxiliary
 table and then delete the records.
 
 Satyam
 
 - Original Message -
 From: Rahul Sitaram Johari [EMAIL PROTECTED]
 To: Mark markw@mohawksoft.com; PHP php-general@lists.php.net
 Sent: Friday, March 23, 2007 5:24 PM
 Subject: Re: [PHP] Add New Records Only!
 
 
 
 Ave,
 
 Three: Insert everything and remove duplicates later.
 
 Out of the suggested options, this option is sounding the most sane
 attainable on my end. I don't have a complete grip on how to
 accomplish
 this, but certainly sounds feasible. Let me look at ways to achieve
 this.
 
 Thanks!
 
 On 3/23/07 11:36 AM, Mark markw@mohawksoft.com wrote:
 
 Rahul Sitaram Johari wrote:
 
 As far as I can see, there is probably only three ways to do this:
 
 One: Make sure your dbase system contains unique primary key
 capability,
 and
 use it to avoid duplicates.
 Two: query for the row, if it isn't there insert it. (You'll have
 to deal
 with concurrency with locking or something)
 Three: Insert everything and remove duplicates later.
 
 Ave,
 
 Let me explain what I¹m trying to do. Unfortunately it¹s not a
 very
 simple
 Add/Update transaction.
 Basically I gather records from multiple mySQL tables and add them
 to a
 DBF
 (dbase) database.  I wrote a code which was able to accomplish
 this
 without any problems and the add_records goes very smooth.
 
 However, I have to modify this program now so that only ³New²
 records,
 i.e., records that have not yet been transferred, are added into
 the
 DBF.
 In other words, any records that are being added, which already
 exist in
 the DBF, should not be added.
 
 If it were just adding records from one mySQL to another mySQL, I
 could
 easily use INSERT IGNORE or the Unique Key fundamental ­ however,
 since
 I¹m adding from multiple mySQL tables into DBF, I¹m not sure how
 to go
 about doing this.
 
 Here¹s my code that takes records from multiple mySQL tables and
 adds
 them
 to a DBF.
 
 // define the array with mySQL Table Names  Identifier
 $tChoice = array(
lodispo = VB,
lodispo_osma = ATL,
lodispo_osmh = HOU,
lodispo_osmn = NSV,
lodispo_osmp = PAA,
lodispo_osmj = JAX,
lodispo_osmt = TPA,
lodispo_dmam = MET,
lodispo_osmf = FTM,
lodispo_hfglend = GLEND,
   lodispo_hfmesa = MESA,
   lodispo_hfphenx = PHENX,
 );
 
 
 // open DBF in read-write mode
 $db2 = dbase_open($theDBFfile, 2);
 if (!$db2) {
   echo BRBRSTRONGFatal Error:/STRONG Unable to open
 databaseBRBR;
   exit;
 }
 
 else {
 
 // Let's Run Array Loops!
 foreach ($tChoice as $tblQ = $bxQ) {
 
 // connect to mySQL tables one by one
 mysql_select_db($database_imslead_transfer,
 $imslead_transfer); $query_loDispo = SELECT * FROM
 $tblQ;
 $loDispo = mysql_query($query_loDispo,
 $imslead_transfer) or
 die(mysql_error());
 $row_loDispo = mysql_fetch_assoc($loDispo);
 $totalRows_loDispo = mysql_num_rows($loDispo);
 
 // write mySql data to Dbf
 do {
  dbase_add_record($db2, array(
  $row_loDispo['phone'],
  $row_loDispo['comments'],
  $row_loDispo['starttime'],
  $row_loDispo['endtime'],
  $row_loDispo['dispo'],
  $row_loDispo['loanofficer'],
  $row_loDispo['verifier'],
  $bxQ));
  } while ($row_loDispo =
 mysql_fetch_assoc($loDispo));
 }
 
 dbase_close($db2);
 }
 
 Any suggestions would be highly appreciated.
 
 

Re: [PHP] Rewriting urls

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 12:14 pm, [EMAIL PROTECTED] wrote:
 I am having some problems getting my mod_rewrite to work on my
 development
 server. On my
 production server (linux) this works fine. But on my development
 server it
 woun't work.

 I have a file basicpage.php that is located in the webroot. I then
 have
 a .htaccess file
 with the following content:


 #DirectoryIndex index.php index.html
 #Options +FollowSymLinks
 #RewriteBase /relative/web/path/

 IfModule mod_rewrite.c
   RewriteEngine On
   RewriteRule ^article/([0-9]+)/[-a-zA-Z]+$ /basicpage.php?id=$1
 /IfModule


 The rewrite works as expected on the production server, but on the
 development
 server it
 don't want to work. I also tried it on a windows machine but it don't
 want to
 work there
 either.

 Any suggestions/insights?

Two Suggestions:

Check AllowOverride in httpd.conf

Ask on an Apache list, since there is zero PHP here.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Newline and tab characters

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 6:54 am, Arno Kuhl wrote:
 I've just noticed that \r\n and \t characters create a space when
 rendered in the browser (tested in IE and Firefox). I'd always thought
 the
 browser would ignore these characters.

No.

HTML collapses any run of whitespace to a single space character.

It does something akin to:
$html = preg_replace(|\\s+|,  , $html);
on each chunk of non-tag content.

It does not ever ignore whitespace in content.

 This wouldn't normally be a
 problem
 but the wysiwyg html editor in the cms I'm using tries to be friendly
 by
 formatting the html code, so something like

 span style=\COLOR: #af0e14\get/spanspan style=\COLOR:
 #33\online/span

 becomes

 \r\n\t\tspan style=\COLOR: #af0e14\get/span\r\n\t\tspan
 style=\COLOR: #33\online/span

Your WYSIWIG tool is very broken, if the above is correct, since it is
ADDING a bunch of whitespace inside the content.

 Is there a simple way to sort this out or do I need to create a
 function to
 strip these characters before display, checking first that they don't
 occur
 within a pre tag in which case I mustn't strip them.

I'm betting that you have not correctly analyzed what is going on yet,
first and foremost.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gethostbyname () uses old DNS server

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 4:21 am, Kent Tong wrote:
 We have moved our DNS server from one IP to another. But on a Linux
 server, the PHP programs keep using the old DNS server IP. For
 example, for a simple php file:

 ? echo gethostbyname (smtp.cpttm); ?

 When it is run, it tries to lookup smtp.cpttm using the old DNS
 server (I know it using tcpdump). The new DNS server is specified in
 /etc/resolv.conf. If I issue ping smtp.cpttm in a command prompt,
 then tcpdump shows that it is accessing the new DNS server.

 Any idea? Thanks.

Check /etc/hosts

Try doing the same thing from the command line.

And did you re-start apache so PHP could forget any DNS entries in
any cache it might have?  There may be something akin to
clearstatcache for DNS in PHP as well.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: SNMP support on compile from source FastCGI

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 1:47 am, Matt Arnilo S. Baluyos (Mailing Lists)
wrote:
 It's strange though because I don't see an SNMP section on the result
 of a phpinfo();

Almost for sure you still don't have SNMP then.

Check config.log to see if PHP found the snmp libs or not.

Probably not.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OT - How to code a link to download a file (program file)

2007-03-26 Thread Richard Lynch
On Sun, March 25, 2007 8:41 am, Lorin Lund wrote:
 I have a web site where I have posted some programs I have written as
 shareware.

 a href=myprogram-setup.execlick here to download/a

 works great with mozilla but with MS IE it tries to display the
 program.
 What is the simplest way to set it up so that the user just clicks on
 the
 link and the program gets downloaded for storage/execution on their
 system?

http://richardlynch.blogspot.com

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: My own captcha from 2 years ago......

2007-03-26 Thread Richard Lynch
On Sat, March 24, 2007 11:00 pm, Jake McHenry wrote:
 Index.php
 ?php
 session_start();
 header(Refresh: 1);

I dunno what the heck the Refresh header is, but it would not shock
me in the least that your sessions are getting lost because your
browser does the refresh before it processes the cookie that maintains
session state.

A few zillion PHP CAPTCHA implementations use $_SESSION, so it's got
to be you messing up somewhere. :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OT - How to code a link to download a file (program file)

2007-03-26 Thread Rahul Sitaram Johari

Ave,

To be honest, I don't think it's OT.

I ran into a similar problem quite a while back, working on a File Manager
application programmed in PHP/mySQL. I used the following 'fore-download'
header in php which assured the user present with a Save Dialog box to
download the file, and not open the file in IE.

?php
header(Content-Description: File Transfer);
header(Content-Type: application/force-download);
header(Content-Disposition: attachment; filename=.basename($F));
@readfile($F);
?

$F was the filename passed as a variable.

~~~
Rahul Sitaram Johari
CEO, Twenty Four Seventy Nine Inc.

W: http://www.rahulsjohari.com
E: [EMAIL PROTECTED]

³I morti non sono piu soli ... The dead are no longer lonely²


On 3/26/07 3:43 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 On Sun, March 25, 2007 8:41 am, Lorin Lund wrote:
 I have a web site where I have posted some programs I have written as
 shareware.
 
 a href=myprogram-setup.execlick here to download/a
 
 works great with mozilla but with MS IE it tries to display the
 program.
 What is the simplest way to set it up so that the user just clicks on
 the
 link and the program gets downloaded for storage/execution on their
 system?
 
 http://richardlynch.blogspot.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: My own captcha from 2 years ago......

2007-03-26 Thread Richard Lynch
If the code is embedded in the audio filename, or as part of the HTML,
the CAPTCHA itself is kinda useless to a serious attack.  The attacker
will simply read the code from the HTML/URL

You need the secret code to never actually leave your server for it to
stay secret.

That said, CAPTCHA can usually be broken by OCR by a serious attacker,
though that takes a little longer than simply reading the code from
HTML.

Presumably somebody somewhere could (or already has) hook up voice
recognition to an audio CAPTCHA and defeat that as well.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: SNMP support on compile from source FastCGI

2007-03-26 Thread Erik Jones


On Mar 26, 2007, at 2:40 PM, Richard Lynch wrote:


On Mon, March 26, 2007 1:47 am, Matt Arnilo S. Baluyos (Mailing Lists)
wrote:

It's strange though because I don't see an SNMP section on the result
of a phpinfo();


Almost for sure you still don't have SNMP then.

Check config.log to see if PHP found the snmp libs or not.

Probably not.


Also, when you recompile, make sure you at least 'make clean'.  'make  
distclean' would be good, too


erik jones [EMAIL PROTECTED]
software developer
615-296-0838
emma(r)





RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Richard Lynch
On Sun, March 25, 2007 9:49 am, Jake McHenry wrote:
 Do I call the image creation file in an html img tag? I've tried a
 bunch of
 things, and this is the only way I've been able to display the image
 inline
 so far, without the image headers blocking the rest of my output

There is no such thing as inline image, so just forget that.

Yes, you just use a SRC in an IMG tag to point to a PHP script.

That PHP script can just use session_start() and get the secret key.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Richard Lynch
On Sun, March 25, 2007 9:02 pm, Jake McHenry wrote:
 In image.php is this:

 ?php
 session_start();

 ..captcha code..
 $_SESSION['code'] = rand(blahblahblah) to get the random code

Arooo?

Don't randomize the code you're going to put on the image here.

Make up a secret/random/obvious 'code' at the very beginning of the
process and DON'T CHANGE IT.


-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Rewriting urls

2007-03-26 Thread Tijnema !

On 3/26/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Mon, March 26, 2007 12:14 pm, [EMAIL PROTECTED] wrote:
 I am having some problems getting my mod_rewrite to work on my
 development
 server. On my
 production server (linux) this works fine. But on my development
 server it
 woun't work.

 I have a file basicpage.php that is located in the webroot. I then
 have
 a .htaccess file
 with the following content:


 #DirectoryIndex index.php index.html
 #Options +FollowSymLinks
 #RewriteBase /relative/web/path/

 IfModule mod_rewrite.c
   RewriteEngine On
   RewriteRule ^article/([0-9]+)/[-a-zA-Z]+$ /basicpage.php?id=$1
 /IfModule


 The rewrite works as expected on the production server, but on the
 development
 server it
 don't want to work. I also tried it on a windows machine but it don't
 want to
 work there
 either.

 Any suggestions/insights?

Two Suggestions:

Check AllowOverride in httpd.conf

Ask on an Apache list, since there is zero PHP here.


OMG, this problem is already solved, and you're telling him he has to
go to the apache list :P

Tijnema


--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
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



Re: [PHP] gethostbyname () uses old DNS server

2007-03-26 Thread Tijnema !

On 3/26/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Mon, March 26, 2007 4:21 am, Kent Tong wrote:
 We have moved our DNS server from one IP to another. But on a Linux
 server, the PHP programs keep using the old DNS server IP. For
 example, for a simple php file:

 ? echo gethostbyname (smtp.cpttm); ?

 When it is run, it tries to lookup smtp.cpttm using the old DNS
 server (I know it using tcpdump). The new DNS server is specified in
 /etc/resolv.conf. If I issue ping smtp.cpttm in a command prompt,
 then tcpdump shows that it is accessing the new DNS server.

 Any idea? Thanks.

Check /etc/hosts

Try doing the same thing from the command line.

And did you re-start apache so PHP could forget any DNS entries in
any cache it might have?  There may be something akin to
clearstatcache for DNS in PHP as well.


This problem is also solved already Richard...

Tijnema


--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
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



Re: [PHP] OT - How to code a link to download a file (program file)

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 2:49 pm, Rahul Sitaram Johari wrote:
 header(Content-Type: application/force-download);

header(Content-type: asfdsgfhrsiu/luhgireughinfibvn);

would work equally well as application/force-download

 header(Content-Disposition: attachment; filename=.basename($F));
 @readfile($F);
 ?

 $F was the filename passed as a variable.

And if $F is set to /etc/passwd what does your script hand out?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OT - How to code a link to download a file (program file)

2007-03-26 Thread Rahul Sitaram Johari

I was actually going through your blogspot on the subject and figured quite
a few flaws in my code and am re-writing it as we speak.

But believe it or not Richard, at the time I was researching this, and this
is about 2 years back, I was provided the code that I have in this very
mailing list amidst a long  elaborate discussion  post replies by various
members - and quite honestly - once I took the suggested code  saw it
worked as my solution, I really didn't dig any further or try to find flaws
with it!


On 3/26/07 4:06 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 On Mon, March 26, 2007 2:49 pm, Rahul Sitaram Johari wrote:
 header(Content-Type: application/force-download);
 
 header(Content-type: asfdsgfhrsiu/luhgireughinfibvn);
 
 would work equally well as application/force-download
 
 header(Content-Disposition: attachment; filename=.basename($F));
 @readfile($F);
 ?
 
 $F was the filename passed as a variable.
 
 And if $F is set to /etc/passwd what does your script hand out?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add New Records Only!

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 2:28 pm, Rahul Sitaram Johari wrote:
 Another option would be to just create a UNIQUE INDEX on the fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.

 Could you possibly elaborate on this?
 Things I'm trying are still not working out the way or want to, or
 efficiently. So still looking for a solution.

create unique index no_duplicates on whatever(field1, field2, field3);

$query = insert into whatever (field1, field2, field3)
values('$field1_sql', '$field2_sql', '$field3_sql');
$insert = mysql_query($query, $connection);
if (!$insert  mysql_errno($connection) == 1062){
  //this is a duplicate insert that failed. do whatever you want here
}
elseif (!$insert){
  //something else went wrong with the insert.
  //provide usual debugging error handling here
}
else{
  //everything went fine here
}


-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] memory management

2007-03-26 Thread Stan Kuhn
Hi guys,

I work with hierarchical world areas organization in my php script.

It consumes a lot of memory so I'm trying to optimize it.

The more I try the worse it is ;o)

Consider following code:

general::debug(make_hierarchy,before hier split);
//lets organize areas by parents
foreach ($in_flat_areas as $area_data)
{
  $areas_by_parents[$area_data['parent_id']][]=$area_data;
}
unset($in_flat_areas);
general::debug(make_hierarchy,after hier split);


OUTPUT:
15:25:09 | alloc:14114120 ( 1109632 8.53% rise), peak:15065104 |
make_hierarchy -- before hier split
15:25:09 | alloc:15242104 ( 1127904 7.99% rise), peak:16192000 |
make_hierarchy -- after hier split

It has risen by 1.1M that's fine.

If I change line 
foreach ($in_flat_areas as $area_data)
to this
foreach ($in_flat_areas as $area_data)
which I would consider less mamory wasteful cos of using reference instead
copying and allocating more memory the results are following:

OUTPUT2:
15:28:18 | alloc:14114120 ( 1109632 8.53% rise), peak:15065104 |
make_hierarchy -- before hier split
15:28:18 | alloc:22059472 ( 7945352 56.29% rise), peak:29819936 |
make_hierarchy -- after hier split

8M rise? 

And check out this
Commenting out line 
unset($in_flat_areas);
is giving following results:

15:29:28 | alloc:14114048 ( 1109544 8.53% rise), peak:15065120 |
make_hierarchy -- before hier split
15:29:28 | alloc:29820784 ( 15706656 111.28% rise), peak:29823560 |
make_hierarchy -- after hier split

15M rise?  


Then after this I'm calling quite short recursive function that returns
hierarchical organization of the areas.

Lets look at that:


  /**
   * builds hierarchy of children from given area array organized by parents
   *
   * @param $in_parent id of area for which to find children
   * @param $in_areas_by_parents all areas indexed by parent id
   * @return false or array of children
   */
  function get_children_hierarchy($in_parent,$in_areas_by_parents)
  {

if (!empty($in_areas_by_parents[$in_parent]))
{ 
  foreach ($in_areas_by_parents[$in_parent] as $k = $area_data) 
  {

$children_array[$area_data['id']]=$area_data;

//find children of these ones
if
(($children=$this-get_children_hierarchy($area_data['id'],$in_areas_by_pare
nts))!==false)
  $children_array+=$children;

unset($area_data);
  }
  return $children_array;
}
else 
  return false;
  }


Function is called recursively, input parameters are passed by reference
presumably not to waste memory.

//lets loop first level
$top_parent = 0;
$in_out_hier_areas=$this-get_children_hierarchy($top_parent,$areas_by_paren
ts);
#unset ($areas_by_parents);
general::debug(make_hierarchy,after all);

Here are some numbers before and after calling the function

15:38:32 | alloc:29531600 ( 15706392 113.61% rise), peak:29534376 |
make_hierarchy -- after hier split
15:38:32 | alloc:38346304 ( 8814560 29.85% rise), peak:39309800 |
make_hierarchy -- after all

9M rise, quite a lot but that's not a point. Look what happens if I change
function definition to
function get_children_hierarchy($in_parent,$in_areas_by_parents) 

just passing input parameters by copying values

results:

15:43:05 | alloc:29532176 ( 15720544 113.82% rise), peak:29534952 |
make_hierarchy -- after hier split
15:43:05 | alloc:38347072 ( 8814752 29.85% rise), peak:39110480 |
make_hierarchy -- after all

No difference. 9M rise again. The peak is even few bytes less isn't it.



After all this there is return of result from function where all this si
happening...

If I unset the only variable that have been assigned in this function
Which is $areas_by_parents, I manage to put down memory usage to 
15:51:33 | alloc:30094376 ( 272832 0.91% rise), peak:39399768 |
make_hierarchy -- after all

Result of the function has been assigned to in_out variable that has been
passed by reference to the function $in_out_hier_areas.

If this is consuming 
30094376 - 14114048 aprox 15M that is difference from start to the end of
the function

Why after returning from the function I getting this results:
15:57:23 | alloc:13559376 ( -16536392 -54.95% rise), peak:39399384 | after
make hierarchy

Where is php wasting so much memory? How to control it? How to free up this
memory when needed? Should I stop using referenced variables? I'm a bit
confused.

Thanks
Stan.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: combine empty and trim

2007-03-26 Thread Richard Lynch
On Mon, March 26, 2007 10:50 am, Richard Davey wrote:
 Tim wrote:

 Ross schrieb:
 I want to trim any whitepace and check if it is empty in the same
 line this is not working.

 if (empty(trim($_POST['_createcategory']))) {
 Hi,

 try this:

 if (isset($_POST['_createcategory']))
 {
   $value = trim($_POST['_createcategory']);
   if (empty($value))
   {

 Be very careful with empty(). It doesn't do exactly what it says on
 the
 tin. For example if your _createcategory POST value contained a zero,
 the empty() check will fail in the above instance, giving a false
 result.

Unless you are using a different version of PHP where it did something
different...
http://php.net/empty

I have never figured out why people keep using empty() and why its
behaviour keeps changing around...
[shrug]

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add New Records Only!

2007-03-26 Thread Rahul Sitaram Johari

I'm exporting the data from mySQL table(s) into a dbase DBF table. The
unique index you're talking about should be in the DBF end, if I'm not
mistaken - but I'm not sure how to do that, and if that will help mySQL to
get that error and fail the second insert.

Unless I'm not getting this right.


On 3/26/07 4:13 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 On Mon, March 26, 2007 2:28 pm, Rahul Sitaram Johari wrote:
 Another option would be to just create a UNIQUE INDEX on the fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.
 
 Could you possibly elaborate on this?
 Things I'm trying are still not working out the way or want to, or
 efficiently. So still looking for a solution.
 
 create unique index no_duplicates on whatever(field1, field2, field3);
 
 $query = insert into whatever (field1, field2, field3)
 values('$field1_sql', '$field2_sql', '$field3_sql');
 $insert = mysql_query($query, $connection);
 if (!$insert  mysql_errno($connection) == 1062){
   //this is a duplicate insert that failed. do whatever you want here
 }
 elseif (!$insert){
   //something else went wrong with the insert.
   //provide usual debugging error handling here
 }
 else{
   //everything went fine here
 }
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Computing and calculating dates

2007-03-26 Thread Richard Lynch
On Sun, March 25, 2007 12:46 pm, Otto Wyss wrote:
 Sorry that doesn't work with dates like 1.4.2007.

list($d, $m, $y) = explode('.', '1.4.2007');
$unixtime = mktime(1, 0, 0, $m, $d, $y);

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Performance: While or For loop

2007-03-26 Thread Richard Lynch
On Sat, March 24, 2007 4:52 am, Tijnema ! wrote:

 That means that at 1000 iterations, you are saving how much time?

 .00026 seconds?
 .4 seconds?

 Puhleaze.

 Well, if you execute this script 1000 times, you would get a
 difference of 2.6 seconds?
 But if every microseconds counts for your script, then you should now
 about this.

No.

Re-read the benchmards.

At 1000 iterations you're looking at .000xx seconds.

At a MILLION iterations, you're looking at 0.xx seconds

At a TEN MILLION iterations, you've broken the 1-second barrier.

How many PHP scripts do a for or while loop 10 million iterations?

xx is either 26 or 4, depending on whose benchmarks you believe.

Running tests with 10 million iterations to benchmark is great for
removing overhead margin of error.  It's also great to look at exactly
how many times you'd have to do something to make a significant
savings.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add New Records Only!

2007-03-26 Thread Richard Lynch
I have no idea what DBF is, but if the data is already in MySQL with
duplicates, you'll need to take everything I just said, and
translate it to DBF.

If it cannot be translated to DBF because DBF has no unique indeces,
you could, perhaps, create a TEMP table in MySQL, with the unique
index, insert rows one by one, and silently ignore the ones that fail
to insert.

Then export the temp table to DBF.

On Mon, March 26, 2007 3:19 pm, Rahul Sitaram Johari wrote:

 I'm exporting the data from mySQL table(s) into a dbase DBF table. The
 unique index you're talking about should be in the DBF end, if I'm not
 mistaken - but I'm not sure how to do that, and if that will help
 mySQL to
 get that error and fail the second insert.

 Unless I'm not getting this right.


 On 3/26/07 4:13 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 On Mon, March 26, 2007 2:28 pm, Rahul Sitaram Johari wrote:
 Another option would be to just create a UNIQUE INDEX on the
 fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.

 Could you possibly elaborate on this?
 Things I'm trying are still not working out the way or want to, or
 efficiently. So still looking for a solution.

 create unique index no_duplicates on whatever(field1, field2,
 field3);

 $query = insert into whatever (field1, field2, field3)
 values('$field1_sql', '$field2_sql', '$field3_sql');
 $insert = mysql_query($query, $connection);
 if (!$insert  mysql_errno($connection) == 1062){
   //this is a duplicate insert that failed. do whatever you want
 here
 }
 elseif (!$insert){
   //something else went wrong with the insert.
   //provide usual debugging error handling here
 }
 else{
   //everything went fine here
 }


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Add New Records Only!

2007-03-26 Thread Rahul Sitaram Johari

DBF is native dbase databases, used by foxpro etcetera.
But anyhow, I think what you've suggested is what I'll have to do. Take
records from all my mySQL table(s) and put Unique records (based on your
unique identifier exception code) into a temp mySQL table and then simply
transfer the records into the dbase dbf.

Just for your info, I'm using the dbase() functions in php, using
dbase_add_records() to add the records into the dbf.

I'll give this a try, use your code, and more then likely it should work.

Thanks!


On 3/26/07 4:39 PM, Richard Lynch [EMAIL PROTECTED] wrote:

 I have no idea what DBF is, but if the data is already in MySQL with
 duplicates, you'll need to take everything I just said, and
 translate it to DBF.
 
 If it cannot be translated to DBF because DBF has no unique indeces,
 you could, perhaps, create a TEMP table in MySQL, with the unique
 index, insert rows one by one, and silently ignore the ones that fail
 to insert.
 
 Then export the temp table to DBF.
 
 On Mon, March 26, 2007 3:19 pm, Rahul Sitaram Johari wrote:
 
 I'm exporting the data from mySQL table(s) into a dbase DBF table. The
 unique index you're talking about should be in the DBF end, if I'm not
 mistaken - but I'm not sure how to do that, and if that will help
 mySQL to
 get that error and fail the second insert.
 
 Unless I'm not getting this right.
 
 
 On 3/26/07 4:13 PM, Richard Lynch [EMAIL PROTECTED] wrote:
 
 On Mon, March 26, 2007 2:28 pm, Rahul Sitaram Johari wrote:
 Another option would be to just create a UNIQUE INDEX on the
 fields
 you think should be unique, and then your second insert is gonna
 fail, and you can just ignore that.
 
 Could you possibly elaborate on this?
 Things I'm trying are still not working out the way or want to, or
 efficiently. So still looking for a solution.
 
 create unique index no_duplicates on whatever(field1, field2,
 field3);
 
 $query = insert into whatever (field1, field2, field3)
 values('$field1_sql', '$field2_sql', '$field3_sql');
 $insert = mysql_query($query, $connection);
 if (!$insert  mysql_errno($connection) == 1062){
   //this is a duplicate insert that failed. do whatever you want
 here
 }
 elseif (!$insert){
   //something else went wrong with the insert.
   //provide usual debugging error handling here
 }
 else{
   //everything went fine here
 }
 
 
 --
 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



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread Jake McHenry
The try again button doesn't work...

And geez I had this working ok the entire time When I saw yours it
hit me... I don't have a form.  It would never echo out the code to
match whats in the picture... When the form is submitted it will check.. But
I didn't have it on a form... I was just playing with the images.. And
trying to get it to echo out whats in the pic So I sat here and did this
for basically nothing... Someone smack me.. lol 

 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED] 
 Sent: Monday, March 26, 2007 1:11 PM
 To: Brad Fuller; php-general@lists.php.net
 Subject: RE: [PHP] My own captcha from 2 years ago..
 
 At 10:59 AM -0400 3/26/07, Brad Fuller wrote:
 
 echo 'img src=image.php';
 
 This does not run or call image.php.
 
 This line of code sends this output to the browser.
 
 Brad:
 
 Yes, but the browser runs the code by trying to load an image.
 
 Check this out:
 
 http://sperling.com/examples/assorted-captcha/index.php
 
 The first Captcha is the typical type and the image shown is created 
 by captcha.php via a simple img tag:
 
 img src=captcha.php
 
 In this example, the key for this is passed via sessions and is not 
 included in a cookie nor dependant upon the value of the session id.
 
 Refresh the page and new values are shown because it's the tag that 
 causes the captcha.php script to run.
 
 Don't mind the Audio Captcha there, I have a better one.
 
 Cheers,
 
 tedd
 
 -- 
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.446 / Virus Database: 268.18.18/733 - Release 
 Date: 3/25/2007 11:07 AM
  
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.18/733 - Release Date: 3/25/2007
11:07 AM
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: My own captcha from 2 years ago......

2007-03-26 Thread Jake McHenry
Refresh was at 1 sec... Cause I was just playing with the images... And I
just figured it out... And responded to the list... But again... I had it
working the entire time, but I didn't have a form to submit something to
compare it to, which when I do that, it works, but it will never echo out
what is currently in the pic 

 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED] 
 Sent: Monday, March 26, 2007 3:49 PM
 To: Jake McHenry
 Cc: 'itoctopus'; php-general@lists.php.net
 Subject: RE: [PHP] Re: My own captcha from 2 years ago..
 
 On Sat, March 24, 2007 11:00 pm, Jake McHenry wrote:
  Index.php
  ?php
  session_start();
  header(Refresh: 1);
 
 I dunno what the heck the Refresh header is, but it would not shock
 me in the least that your sessions are getting lost because your
 browser does the refresh before it processes the cookie that maintains
 session state.
 
 A few zillion PHP CAPTCHA implementations use $_SESSION, so it's got
 to be you messing up somewhere. :-)
 
 -- 
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?
 
 -- 
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.446 / Virus Database: 268.18.18/733 - Release 
 Date: 3/25/2007 11:07 AM
  
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.18/733 - Release Date: 3/25/2007
11:07 AM
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: My own captcha from 2 years ago......

2007-03-26 Thread tedd

At 2:53 PM -0500 3/26/07, Richard Lynch wrote:

If the code is embedded in the audio filename, or as part of the HTML,
the CAPTCHA itself is kinda useless to a serious attack.  The attacker

will simply read the code from the HTML/URL

I have not finished with the blind testing of my audio Captcha, so I 
would rather not show an example at the moment. But the sound file is 
assembled on the fly and always has the same name -- so, reading 
the file access.mp3 doesn't tell the hacker anything.


The key is in sessions and as such is relatively safe. Communication 
between application and Captcha contains a confirmable unique token. 
I think the technique is pretty secure.



You need the secret code to never actually leave your server for it to
stay secret.

That said, CAPTCHA can usually be broken by OCR by a serious attacker,
though that takes a little longer than simply reading the code from
HTML.

Presumably somebody somewhere could (or already has) hook up voice
recognition to an audio CAPTCHA and defeat that as well.


Well for that matter, a hacker could hire cheap labor read or listen to it.

The point is to make it difficult for bots to get to it. Anything a 
computer can put create, another computer can interpret. The 
technology lag between one to the other is always only temporary and 
therein lies some temporary relief.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] My own captcha from 2 years ago......

2007-03-26 Thread tedd

At 2:56 PM -0500 3/26/07, Richard Lynch wrote:

On Sun, March 25, 2007 9:49 am, Jake McHenry wrote:

 Do I call the image creation file in an html img tag? I've tried a
 bunch of
 things, and this is the only way I've been able to display the image
 inline
 so far, without the image headers blocking the rest of my output


There is no such thing as inline image, so just forget that.

Yes, you just use a SRC in an IMG tag to point to a PHP script.

That PHP script can just use session_start() and get the secret key.



Yep, that's the way to do it.

Create a key at the start, place it in a session, call your Captcha 
image maker via src, and display the image.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] usage of flock

2007-03-26 Thread Richard Lynch
On Fri, March 23, 2007 10:34 pm, Myron Turner wrote:
 You can do it with flock, but then you end up sooner or later with a
 locked file from an exit or killed script, and then you have to
 know
 to remove locks older than X minutes.

 You could also just do a mkdir for your lock, and check its
 filemtime.  You could even use touch within loop of the script to
 make sure the script is still going, and safely assume that any lock
 older than X seconds is stale and can be ignored/removed.

 I've never used locks in PHP, but have used them in Perl.  In Perl a
 lock is automatically released on exit or when the locked file is
 closed.  Is that not the same in PHP?  According the the man page for
 the C version of flock, it too releases the lock on close and C's exit
 closes all streams.  So, Perl is consistent with that.  Just wondering
 for myself it this isn't the case with PHP, in case I ever  want to
 use
 a lock.

It is the case, just as in C or Perl, that it's SUPPOSED to shut down
nicely and remove the lock...

When, not if, when, something goes terribly wrong, and you manage to
segfault PHP/Apache, do you want to have to remember to manually nuke
the flock somehow, or do you just want to code it from the get-go to
ignore locks older than X time? :-)

No matter how carefully you program your locks, sooner or later,
you'll have to have some meta programming about the locks to deal
with an inconsistent state of locks.

At least, that's been my experience so far...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] usage of flock

2007-03-26 Thread Yvan Strahm

On 3/23/07, Richard Lynch [EMAIL PROTECTED] wrote:


On Fri, March 23, 2007 7:52 pm, Yvan Strahm wrote:
 I am confused with the flock function and its usage. I have jobs which
 are
 stored in a database, these jobs are run by a series of job_runners
 scripts
 but sometimes the job_runners stop ( server or php crash-down). So i
 put a
 job_controller in crontab to check  regularly if the  runners run. But
 after
 a while I have a bunch of job_controller running, so to avoid that I
 tried
 to use flock.

 I try to put this in the job_controller:

 $wouldblock=1;
 $f=fopen(controller.lock, r);
 flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die(Error! cant lock!);

 hoping that as long as the first job_controller run or don't close the
 file
 handle, a second job_controller won't be able to lock the
 controller.lockfile and die, but it didn't work.

 I also try this:

 $wouldblock=1;
 $f=fopen(controller.php, r);
 flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die(Error! cant lock!);

 hoping the first job_controller will lock it-self, but it didn't work.

 I also thought of writing in the lock file the PID of the first
 job_controller and then compare it and if it doesn't match then die,
 but my
 main concern is , if the server crash down the surviving lock file
 will
 prevent any job_controller to start.

 So how could prevent multiple instance of the same script? Is flock
 the best
 way?

You can do it with flock, but then you end up sooner or later with a
locked file from an exit or killed script, and then you have to know
to remove locks older than X minutes.

You could also just do a mkdir for your lock, and check its
filemtime.  You could even use touch within loop of the script to
make sure the script is still going, and safely assume that any lock
older than X seconds is stale and can be ignored/removed.

A final option is to use 'exec' to figure out if another process is
running already:
//bail out if it's already running:
$pid = getmypid();
$command = /bin/ps aux | grep  . __FILE__ .  | grep -v grep ;
exec($command, $existing, $error);
if ($error) die(OS Error: $error\n . implode(\n, $existing) . \n);
$other_count = 0;
foreach($existing as $procline){
  if (!strstr($procline,  $pid )) $other_count++;
}
if ($other_count) exit;

This allows you to be sure there is always one, and only one, running
prcess or this file, with no assumptions about lock files maybe being
stale.

I use different ones at different times, depending on what the process
needs to do, and how critical it is that it runs frequently.

--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?




Thanks very much for the code, it works nicely. Just have to adjust the
command, __FILE__ returns the absolute path to the script but ps returns
only the relative path.
So the existing array was empty.
Thanks again

yvan


Re: [PHP] usage of flock

2007-03-26 Thread Yvan Strahm

On 3/23/07, Myron Turner [EMAIL PROTECTED] wrote:


Richard Lynch wrote:
 On Fri, March 23, 2007 7:52 pm, Yvan Strahm wrote:

 I am confused with the flock function and its usage. I have jobs which
 are
 stored in a database, these jobs are run by a series of job_runners
 scripts
 but sometimes the job_runners stop ( server or php crash-down). So i
 put a
 job_controller in crontab to check  regularly if the  runners run. But
 after
 a while I have a bunch of job_controller running, so to avoid that I
 tried
 to use flock.

 I try to put this in the job_controller:

 $wouldblock=1;
 $f=fopen(controller.lock, r);
 flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die(Error! cant lock!);

 hoping that as long as the first job_controller run or don't close the
 file
 handle, a second job_controller won't be able to lock the
 controller.lockfile and die, but it didn't work.

 I also try this:

 $wouldblock=1;
 $f=fopen(controller.php, r);
 flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die(Error! cant lock!);

 hoping the first job_controller will lock it-self, but it didn't work.

 I also thought of writing in the lock file the PID of the first
 job_controller and then compare it and if it doesn't match then die,
 but my
 main concern is , if the server crash down the surviving lock file
 will
 prevent any job_controller to start.

 So how could prevent multiple instance of the same script? Is flock
 the best
 way?


 You can do it with flock, but then you end up sooner or later with a
 locked file from an exit or killed script, and then you have to know
 to remove locks older than X minutes.

 You could also just do a mkdir for your lock, and check its
 filemtime.  You could even use touch within loop of the script to
 make sure the script is still going, and safely assume that any lock
 older than X seconds is stale and can be ignored/removed.

I've never used locks in PHP, but have used them in Perl.  In Perl a
lock is automatically released on exit or when the locked file is
closed.  Is that not the same in PHP?  According the the man page for
the C version of flock, it too releases the lock on close and C's exit
closes all streams.  So, Perl is consistent with that.  Just wondering
for myself it this isn't the case with PHP, in case I ever  want to use
a lock.

It's not clear to me from the original question, Yvan, whether you are
able to get any lock at all.  That is, if you are using LOCK_NB and a
lock is already on the locked file, then the lock will be refused and
the call will return immediately without a lock.  So, the only way to
use LOCK_NB is in a loop.  Generally, this is not recommended, because
in the time the loop gets back to making a second call, another file
might have gotten the lock.  However, in your case this might not
matter, since you are the only one sending out these job controllers,
and eventually all your processes will have had a chance at the lock file.

On the other hand, if you use LOCK_EX, the call will block until a lock
is available.  Again, in your case this might not matter either.  The
danger here is that you will get a process that doesn't shut down.  You
can deal with this by setting an alarm which is caught using a signal
handler that can exit the process.

If you use LOCK_NB with a loop, you can also break out of the loop and
exit after a time as well. You'd probably want to use sleep to time your
loop, not a counter, since the counter might swallow up cpu.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/





The controller script never get lock. I was using the LOCK_NP in a infinite
loop without success.
Richard's code works well so  I guess i will not use flock in this
particular case.

Thanks for your answer

Cheers
yvan


Re: [PHP] syntax question

2007-03-26 Thread itoctopus
Escape it, use either htmlentities (with ENT_QUOTES) or addslashes.

--
itoctopus - http://www.itoctopus.com
Richard Lynch [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Mon, March 26, 2007 9:59 am, Ross wrote:
  Can I put post values directly into insert statements?
 
  $query = INSERT INTO categories (category_name) VALUES
  ('$_POST['cat_name']);

 Sure!

 If you want your webserver to get hacked by the Bad Guys, just go
 right ahead and do that.

 [that was tounge-in-cheek]

 Start reading here:
 http://phpsec.org

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP newbie question on xslt

2007-03-26 Thread Timothy Murphy
I've been trying some of the programs
in the PHP manual at http://www.php.net/manual/en/
in chapters CLXXXI and CLXXXII to work, for example

// Example 2519. Creating an XSLTProcessor

?php

$xml_filename = collection.xml;
$xsl_filename= collection.xsl;

$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc-load($xsl_filename);
$xsl-importStyleSheet($doc);

$doc-load($xml_filename);
echo $xsl-transformToXML($doc);

?

(where I have added the two filenames,
and copied the files collection.x?l from the manual).

When I run PHP I get:

[EMAIL PROTECTED] Test]# php ex2519.php
// Example 2519. Creating an XSLTProcessor

Segmentation fault


I'm running the program under Fedora-6 Linux
with the latest versions of all programs.

Is there something I should have included,
to get the program to run?

Any advice or suggestions gratefully received.

-- 
Timothy Murphy  
e-mail (80k only): tim /at/ birdsnest.maths.tcd.ie
tel: +353-86-2336090, +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] memory management

2007-03-26 Thread Jochem Maas
you hijacked someone else's thread. don't do that.

you are making assuptions about references are correct - the engine is cleverer 
than
you think (Sara Golemon has a nice blog post about this kind of reference
assuption that you might want to look up)

the word is 'because' not 'cos'.

'short recursive functions' don't equate to performant recursive functions,
deep recursion is going to cost you in performance if the data set is large
and/or the structure to be create ends up being deep.

the recursive function could be replaced with a smart while() loop - which would
eliminate the costly recursion whilst giving you the same nested structure.

Stan Kuhn wrote:
 Hi guys,
 
 I work with hierarchical world areas organization in my php script.
 
 It consumes a lot of memory so I'm trying to optimize it.
 
 The more I try the worse it is ;o)
 
 Consider following code:
 
 general::debug(make_hierarchy,before hier split);
 //lets organize areas by parents
 foreach ($in_flat_areas as $area_data)
 {
   $areas_by_parents[$area_data['parent_id']][]=$area_data;
 }
 unset($in_flat_areas);
 general::debug(make_hierarchy,after hier split);
 
 
 OUTPUT:
 15:25:09 | alloc:14114120 ( 1109632 8.53% rise), peak:15065104 |
 make_hierarchy -- before hier split
 15:25:09 | alloc:15242104 ( 1127904 7.99% rise), peak:16192000 |
 make_hierarchy -- after hier split
 
 It has risen by 1.1M that's fine.
 
 If I change line 
 foreach ($in_flat_areas as $area_data)
 to this
 foreach ($in_flat_areas as $area_data)
 which I would consider less mamory wasteful cos of using reference instead
 copying and allocating more memory the results are following:
 
 OUTPUT2:
 15:28:18 | alloc:14114120 ( 1109632 8.53% rise), peak:15065104 |
 make_hierarchy -- before hier split
 15:28:18 | alloc:22059472 ( 7945352 56.29% rise), peak:29819936 |
 make_hierarchy -- after hier split
 
 8M rise? 
 
 And check out this
 Commenting out line 
 unset($in_flat_areas);
 is giving following results:
 
 15:29:28 | alloc:14114048 ( 1109544 8.53% rise), peak:15065120 |
 make_hierarchy -- before hier split
 15:29:28 | alloc:29820784 ( 15706656 111.28% rise), peak:29823560 |
 make_hierarchy -- after hier split
 
 15M rise?  
 
 
 Then after this I'm calling quite short recursive function that returns
 hierarchical organization of the areas.
 
 Lets look at that:
 
 
   /**
* builds hierarchy of children from given area array organized by parents
*
* @param $in_parent id of area for which to find children
* @param $in_areas_by_parents all areas indexed by parent id
* @return false or array of children
*/
   function get_children_hierarchy($in_parent,$in_areas_by_parents)
   {
 
 if (!empty($in_areas_by_parents[$in_parent]))
 { 
   foreach ($in_areas_by_parents[$in_parent] as $k = $area_data) 
   {
 
 $children_array[$area_data['id']]=$area_data;
 
   //find children of these ones
   if
 (($children=$this-get_children_hierarchy($area_data['id'],$in_areas_by_pare
 nts))!==false)
 $children_array+=$children;
   
   unset($area_data);
   }
   return $children_array;
 }
 else 
   return false;
   }
 
 
 Function is called recursively, input parameters are passed by reference
 presumably not to waste memory.
 
 //lets loop first level
 $top_parent = 0;
 $in_out_hier_areas=$this-get_children_hierarchy($top_parent,$areas_by_paren
 ts);
 #unset ($areas_by_parents);
 general::debug(make_hierarchy,after all);
 
 Here are some numbers before and after calling the function
 
 15:38:32 | alloc:29531600 ( 15706392 113.61% rise), peak:29534376 |
 make_hierarchy -- after hier split
 15:38:32 | alloc:38346304 ( 8814560 29.85% rise), peak:39309800 |
 make_hierarchy -- after all
 
 9M rise, quite a lot but that's not a point. Look what happens if I change
 function definition to
 function get_children_hierarchy($in_parent,$in_areas_by_parents) 
 
 just passing input parameters by copying values
 
 results:
 
 15:43:05 | alloc:29532176 ( 15720544 113.82% rise), peak:29534952 |
 make_hierarchy -- after hier split
 15:43:05 | alloc:38347072 ( 8814752 29.85% rise), peak:39110480 |
 make_hierarchy -- after all
 
 No difference. 9M rise again. The peak is even few bytes less isn't it.
 
 
 
 After all this there is return of result from function where all this si
 happening...
 
 If I unset the only variable that have been assigned in this function
 Which is $areas_by_parents, I manage to put down memory usage to 
 15:51:33 | alloc:30094376 ( 272832 0.91% rise), peak:39399768 |
 make_hierarchy -- after all
 
 Result of the function has been assigned to in_out variable that has been
 passed by reference to the function $in_out_hier_areas.
 
 If this is consuming 
 30094376 - 14114048 aprox 15M that is difference from start to the end of
 the function
 
 Why after returning from the function I getting this results:
 15:57:23 | 

Re: [PHP] Performance: While or For loop

2007-03-26 Thread Jake Gardner

He said if you run the /script/ itself 1000 times, not a loop with 1000
iterations. This is quite possible; I am fairly certain there are websites
out there that get accessed well over 1000 times a minute, yes?

So every minute, that website is saving a total of 2.6 seconds to do...
whatever it is websites do in their free time.

In reality, scripts rarely get executed once and then are deleted; they are
used repetitively, and the more a script is used, the more significant the
gain. Claiming to look practically on a small gain /within one execution of
a script/ is impractical in itself.

On 3/26/07, Richard Lynch [EMAIL PROTECTED] wrote:


On Sat, March 24, 2007 4:52 am, Tijnema ! wrote:

 That means that at 1000 iterations, you are saving how much time?

 .00026 seconds?
 .4 seconds?

 Puhleaze.

 Well, if you execute this script 1000 times, you would get a
 difference of 2.6 seconds?
 But if every microseconds counts for your script, then you should now
 about this.

No.

Re-read the benchmards.

At 1000 iterations you're looking at .000xx seconds.

At a MILLION iterations, you're looking at 0.xx seconds

At a TEN MILLION iterations, you've broken the 1-second barrier.

How many PHP scripts do a for or while loop 10 million iterations?

xx is either 26 or 4, depending on whose benchmarks you believe.

Running tests with 10 million iterations to benchmark is great for
removing overhead margin of error.  It's also great to look at exactly
how many times you'd have to do something to make a significant
savings.

--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] short open tags not working even if enabled - lighttpd + fastcgi

2007-03-26 Thread Matt Arnilo S. Baluyos (Mailing Lists)

Hello everyone,

I have a working lighttpd + fastcgi + PHP + eaccelerator installation.
I have also enabled short tags on the /usr/local/lib/php.ini but I'm
having problems with PHP not escaping the short tags.

To better illustrate, my phpinfo() file can be accessed at
http://202.171.164.70/phpinfo.php - if you notice short_open_tag is
set to On.

But when you access a PHP page at
http://202.171.164.70/admin/login.php and try to view the source, the
short open tag is not escaped.

Any reason why this isn't working as expected?

Regards,
Matt

--
Stand before it and there is no beginning.
Follow it and there is no end.
Stay with the ancient Tao,
Move with the present.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Performance: While or For loop

2007-03-26 Thread Travis Doherty
Jake Gardner wrote:

 He said if you run the /script/ itself 1000 times, not a loop with 1000
 iterations. This is quite possible; I am fairly certain there are
 websites
 out there that get accessed well over 1000 times a minute, yes?

 So every minute, that website is saving a total of 2.6 seconds to do...
 whatever it is websites do in their free time.

 In reality, scripts rarely get executed once and then are deleted;
 they are
 used repetitively, and the more a script is used, the more significant
 the
 gain. Claiming to look practically on a small gain /within one
 execution of
 a script/ is impractical in itself.

I still wouldn't go around telling people to re-write all of their code
to use for loops instead of while loops (or whatever was faster for
whatever architecture.)

Keep in mind that .000xx seconds in performance improvement certainly
does make a difference on a site that is accessed millions of times a
day, however, one bug caused by writing code that reads poorly instead
of writing clean code can cost a *lot* more in the end.

- Use what reads easier when deciding if a for/while loop is best.
- Profile your code and find the right places to optimize.

Optimizing code that takes .0001 seconds to run down to .1 seconds
is great, 10x improvement!  Who cares. Find the chunk that takes 0.5
seconds to run and optimize that to 0.05 seconds. 10x improvement still,
except that this time it actually makes a practical difference.

Travis Doherty

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: short open tags not working even if enabled - lighttpd + fastcgi

2007-03-26 Thread Tim

Matt Arnilo S. Baluyos (Mailing Lists) schrieb:

Hello everyone,

I have a working lighttpd + fastcgi + PHP + eaccelerator installation.
I have also enabled short tags on the /usr/local/lib/php.ini but I'm
having problems with PHP not escaping the short tags.

To better illustrate, my phpinfo() file can be accessed at
http://202.171.164.70/phpinfo.php - if you notice short_open_tag is
set to On.

But when you access a PHP page at
http://202.171.164.70/admin/login.php and try to view the source, the
short open tag is not escaped.

Any reason why this isn't working as expected?

Regards,
Matt


Hi,

maybe it's because of the whitespace after the ?.

Try this:
?=$_SERVER['PHP_SELF']; ?

Best regards,
Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP newbie question on xslt

2007-03-26 Thread Miguel J. Jiménez

Timothy Murphy escribió:

I've been trying some of the programs
in the PHP manual at http://www.php.net/manual/en/
in chapters CLXXXI and CLXXXII to work, for example

// Example 2519. Creating an XSLTProcessor

?php

$xml_filename = collection.xml;
$xsl_filename= collection.xsl;

$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc-load($xsl_filename);
$xsl-importStyleSheet($doc);

$doc-load($xml_filename);
echo $xsl-transformToXML($doc);

?

(where I have added the two filenames,
and copied the files collection.x?l from the manual).

When I run PHP I get:

[EMAIL PROTECTED] Test]# php ex2519.php
// Example 2519. Creating an XSLTProcessor

Segmentation fault


I'm running the program under Fedora-6 Linux
with the latest versions of all programs.

Is there something I should have included,
to get the program to run?

Any advice or suggestions gratefully received.

  


Try not to load both xml and xsl in the same $doc variable... use one 
for the xsl and another for the xml. I think you are destroying the dom 
for the xsl before the transform...


--
Miguel J. Jiménez
Área de Internet/XSL/PHP
[EMAIL PROTECTED]



ISOTROL
Edificio BLUENET, Avda. Isaac Newton nº3, 4ª planta.
Parque Tecnológico Cartuja '93, 41092 Sevilla.
Teléfono: 955 036 800 - Fax: 955 036 849
http://www.isotrol.com

Killing is often a part of life. What's hypocritical is to condemn, and then make 
allowances when the situation suits.
Utu-Noranti Pralatong (Farscape 4x17 - A Constellation Of Doubt)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php