php-general Digest 17 May 2006 16:29:30 -0000 Issue 4133

2006-05-17 Thread php-general-digest-help

php-general Digest 17 May 2006 16:29:30 - Issue 4133

Topics (messages 236319 through 236353):

Re: 404 After Setting session.save_path to /tmp
236319 by: Chris
236320 by: Chris
236323 by: Mark Sargent
236324 by: Chris
236325 by: Mark Sargent
236327 by: Chris
236328 by: Mark Sargent
236342 by: Ron Clark

Narorwed down my problem to one statement:
236321 by: John Meyer
236326 by: Paul Novitski

PHPEditIni now supports Linux/Unix
236322 by: Jeremy C O'Connor

A searching problem in lists
236329 by: mickb.free.fr
236331 by: Barry

Re : a searching problem in lists
236330 by: mickb.free.fr
236339 by: Jim Moseby

Converting characters
236332 by: Jonas Rosling
236333 by: Barry

Re: PHP daemons
236334 by: Martin Marques

PHP and mySQL getting smashed...
236335 by: Russell Jones
236336 by: Dave Goodchild
236337 by: Angelo Zanetti
236338 by: Jay Blanchard
236340 by: Alister Bulman
236347 by: Jochem Maas

Re: Regex Help for URL's  [ANSWER]
236341 by: Edward Vermillion

Re: Security Concerns with Uploaded Images:
236343 by: Rory Browne
236344 by: George Pitcher
236353 by: Jason Wong

Ajax (xmlHttpRequest) and session_start() problem.
236345 by: Mathijs
236346 by: Robert Cummings
236348 by: Mathijs
236349 by: Thomas Munz

Warning: chmod(): Operation not permitted ?
236350 by: tedd
236351 by: Jochem Maas
236352 by: John Nichel

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

Mark Sargent wrote:

Jochem Maas wrote:

NO - DONT EVER DO THIS tmp/session files should not be stored in a 
directory that

can be [potentially] read via http.

.htaccess directives can be used to block access to the dir BUT I 
still would recommend

keeping 'tmp' outside of the web root.

just make sure 'tmp' is writable by the user the webserver is running as.


Hi All,

thanx. How do I determine what user httpd is running as? Cheers.


Edit your httpd.conf file and look for user and group.

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

Mark Sargent wrote:

Jochem Maas wrote:

NO - DONT EVER DO THIS tmp/session files should not be stored in a 
directory that

can be [potentially] read via http.

.htaccess directives can be used to block access to the dir BUT I 
still would recommend

keeping 'tmp' outside of the web root.

just make sure 'tmp' is writable by the user the webserver is running as.


Hi All,

thanx. How do I determine what user httpd is running as? Cheers.


I should say check your httpd.conf file for User and Group - they 
are capitalized.


Alternatively:

ps aux | grep httpd
or
ps aux | grep apache

the first column is the user it's running as.

or lastly, probably the quickest way, create a phpinfo page and look for

User/Group

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

Chris wrote:
I should say check your httpd.conf file for User and Group - they 
are capitalized.


Alternatively:

ps aux | grep httpd
yes, did that one and see it as starting as root, then goijg to daemon. 
Now, if I add daemon to the root group, isn't that a security issue? 
Should I create a new group? Little confused? Cheers.


Mark Sargent.
---End Message---
---BeginMessage---

Mark Sargent wrote:

Chris wrote:

I should say check your httpd.conf file for User and Group - they 
are capitalized.


Alternatively:

ps aux | grep httpd


yes, did that one and see it as starting as root, then goijg to daemon. 
Now, if I add daemon to the root group, isn't that a security issue? 
Should I create a new group? Little confused? Cheers.


Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir

Done.

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

Chris wrote:

Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir

Hi All,

ok, created dir, added htdocs user/group and changed ownership of dir to 
them. Thing I'm gettin is, every time I make an adjustment to either 
php.ini or httpd.conf, and do a restart, I keep getting 

Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Chris

Mark Sargent wrote:

Chris wrote:

I should say check your httpd.conf file for User and Group - they 
are capitalized.


Alternatively:

ps aux | grep httpd


yes, did that one and see it as starting as root, then goijg to daemon. 
Now, if I add daemon to the root group, isn't that a security issue? 
Should I create a new group? Little confused? Cheers.


Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir

Done.

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

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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Mark Sargent

Chris wrote:

Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir

Hi All,

ok, created dir, added htdocs user/group and changed ownership of dir to 
them. Thing I'm gettin is, every time I make an adjustment to either 
php.ini or httpd.conf, and do a restart, I keep getting a 404 error for 
all pages. Which only corrects when doing a reboot of the box. This was 
happening before I just followed your last steps. Thoughts? Cheers.


Mark Sargent.

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



Re: [PHP] Narorwed down my problem to one statement:

2006-05-17 Thread Paul Novitski

At 09:38 PM 5/16/2006, John Meyer wrote:

$sql = INSERT INTO 
BOOKS(CopyrightYear,CoverType,DatePurchased,EditionNumber,ISBNNumber,Notes,Pages,Publisher,LOCNumber) 
VALUES(\ . $_POST[copyrightyear] . \,\ . $_POST[covertype] 
. \,\ . $_POST[datepurchased] . \, . 
$_POST[editionnumber] . ,\ . $_POST[isbn] . \,\ . 
addslashes($_POST[notes]) . \, . 
(isset($_POST[numberofpages])?$_POST[numberofpages]:0) . ,\ . 
$_POST[publisher] . \,\ . $_POST[locnumber] . \);



Okay,  when $_POST[notes] contains quotes, it seems to break the 
series, ie returns an error at that point of the SQL statement, even 
with addslashes(), am I doing something wrong there?



John,

I wasn't able to get your statement to break regardless of the 
content of $_POST[notes], so I'm inclined to think the problem 
doesn't lie with embedded quotes alone.  Try displaying the value of 
$sql when it fails in MySQL.  Without that evidence, your problem 
seems impossible to solve.


I'm suspicious of this conditional expression:

(isset($_POST[numberofpages])?$_POST[numberofpages]:0)

If $_POST[numberofpages] is set but contains non-numeric content, 
the query will fail.


Here are two other points tangential to your question:

By feeding user input directly into an SQL query, you're creating an 
unnecessary vulnerability in your code.  See SQL Injection at 
http://php.net/manual/en/security.database.sql-injection.php


I find the concatenation with escaped quotes messy and difficult to 
proofread and modify.  My example below is somewhat exaggerated for 
effect, but consider using heredoc syntax for ease of reading and a 
couple of custom functions to make strings  numbers SQL-safe:

___

$copyrightyear = prepString($_POST[copyrightyear]);
$covertype = prepString($_POST[covertype]);
$datepurchased = prepString($_POST[datepurchased]);
$editionnumber = prepNumber($_POST[editionnumber]);
$notes = prepString($_POST[notes]);
$numberofpages = prepNumber($_POST[numberofpages]);
$publisher = prepString($_POST[publisher]);
$locnumber = prepString($_POST[locnumber]);


$sql =  heredocSQL
INSERT INTO BOOKS (
CopyrightYear,
CoverType,
DatePurchased,
EditionNumber,
ISBNNumber,
Notes,
Pages,
Publisher,
LOCNumber
) VALUES (
$copyrightyear,
$covertype,
$datepurchased,
$editionnumber,
$notes,
$numberofpages,
$publisher,
$locnumber
);
heredocSQL;
___

Paul 


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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Chris

Mark Sargent wrote:

Chris wrote:


Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir


Hi All,

ok, created dir, added htdocs user/group and changed ownership of dir to 
them. Thing I'm gettin is, every time I make an adjustment to either 
php.ini or httpd.conf, and do a restart, I keep getting a 404 error for 
all pages. Which only corrects when doing a reboot of the box. This was 
happening before I just followed your last steps. Thoughts? Cheers.


Sounds like you're using the wrong script to restart apache.

What command are you using?

Rebooting will most likely pick up the /etc/init.d/apache or 
/etc/init.d/httpd script.


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

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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Mark Sargent

Chris wrote:

Sounds like you're using the wrong script to restart apache.

What command are you using?

service httpd restart


Rebooting will most likely pick up the /etc/init.d/apache or 
/etc/init.d/httpd script.

Have this in /etc/rc.local on Fedora 5,

startApache=/usr/local/apache2/bin/apachectl
if [ -f $startApache ] ; then
$startApache start
fi

and I see that I have left off start at the end of startApache.

Cheers.

Mark Sargent.

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



[PHP] A searching problem in lists

2006-05-17 Thread mickb
Hello,

I'm not a Perl guru so I (still) have problems :-)
I use the following date structure, quite classic : a list of lists. I have
two instances of this structure, let's take a simple example :

list 1 : [ [toto,tata],[toto,titi] ]
list 2 : [ [toto,tutu],[tata,titi],[toto,titi] ]

My question is :
is there an efficient way to make this kind of research :

I want to know if [toto,titi] from list 1 is present in list 2.

Thanks for help.

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



[PHP] Re : a searching problem in lists

2006-05-17 Thread mickb
Oops, sorry for my last mail. Not the good mailing-list :-)

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



[PHP] Re: A searching problem in lists

2006-05-17 Thread Barry

[EMAIL PROTECTED] schrieb:

Hello,

I'm not a Perl guru so I (still) have problems :-)

And this is not a Perl mailinglist so we have the same problem :)

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

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



[PHP] Converting characters

2006-05-17 Thread Jonas Rosling
Hi,
the PHP newbie is here again asking questions.
Is there anyway in PHP to convert none international characters so the are
displayed correct?
In my case I have lots of data in the database with å,ä and ö.

Thanks // Jonas

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



[PHP] Re: Converting characters

2006-05-17 Thread Barry

Jonas Rosling schrieb:

Hi,
the PHP newbie is here again asking questions.
Is there anyway in PHP to convert none international characters so the are
displayed correct?
In my case I have lots of data in the database with å,ä and ö.

Thanks // Jonas

displayed where?
in html with htmlentities.
otherwise you should use a utf-8 encoding

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

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



Re: [PHP] PHP daemons

2006-05-17 Thread Martin Marques

On Tue, 16 May 2006, Richard Lynch wrote:


On Tue, May 16, 2006 6:27 am, Martin Marques wrote:

In the first daemon all I have to do to kill it is execute a
pkill server_name.

But with the new daemon (the object orientaded one) it doesn't die.


After you pkill it, does it still work?


Yes, I can still connect to the socket and send commands to it.


Or is it a zombie?


bugs:~# ps auxw | grep php
root 29327  0.0  0.5  16992  2288 ?SMay15   0:00 
/usr/bin/php -q /usr/local/php/printSocket/printSocket.php
root  4066  0.0  1.3  17424  5352 ?SMay16   0:00 
/usr/bin/php -q /usr/local/php/offline/offlineSocket.php

bugs:~# pkill printSocket.php
bugs:~# ps auxw | grep php
root  4066  0.0  1.3  17424  5352 ?SMay16   0:00 
/usr/bin/php -q /usr/local/php/offline/offlineSocket.php

bugs:~# pkill offlineSocket.php
bugs:~# ps auxw | grep php
root  4066  0.0  1.3  17424  5352 ?SMay16   0:00 
/usr/bin/php -q /usr/local/php/offline/offlineSocket.php



It's possible PHP's shutdown functions trying to close the sockets and
destroy the instances have a bug...

You could try to pastebin the code somewhere.


The code from the socket that accepts the kill is at:

http://bugs.unl.edu.ar/~martin/socket1.phps

The code of the socket that doesn't get killed is here:

http://bugs.unl.edu.ar/~martin/socket2.tar

--
 21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
-
Lic. Martín Marqués |   SELECT 'mmarques' || 
Centro de Telemática|   '@' || 'unl.edu.ar';

Universidad Nacional|   DBA, Programador,
del Litoral |   Administrador
-
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] PHP and mySQL getting smashed...

2006-05-17 Thread Russell Jones

I have a site that is getting 30K+ traffic daily and it is smashing mySQL -
any ideas on what to do to make the mysql connections more efficient, or
anything in general. No bandwidth issue here, just the server getting
killed.


Thanks


Re: [PHP] PHP and mySQL getting smashed...

2006-05-17 Thread Dave Goodchild

I have a site that is getting 30K+ traffic daily and it is smashing mySQL -

any ideas on what to do to make the mysql connections more efficient, or
anything in general. No bandwidth issue here, just the server getting
killed.

...I may be wrong but using persistent connections (mysql_pconnect) may

help. Also, optimise your tables and use the explain command to see how
efficient your queries are.
--
http://www.web-buddha.co.uk

dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css)

look out for project karma, our new venture, coming soon!


Re: [PHP] PHP and mySQL getting smashed...

2006-05-17 Thread Angelo Zanetti

perhaps post some code so we can look at how you doing your queries...


HTH
Angelo Zanetti
Z Logic
www.zlogic.co.za
[c] +27 72 441 3355
[t] +27 21 469 1052
[f] +27 86 681 5885

Dave Goodchild wrote:

I have a site that is getting 30K+ traffic daily and it is smashing mySQL -


any ideas on what to do to make the mysql connections more efficient, or
anything in general. No bandwidth issue here, just the server getting
killed.

...I may be wrong but using persistent connections (mysql_pconnect) may


help. Also, optimise your tables and use the explain command to see how
efficient your queries are.


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



RE: [PHP] PHP and mySQL getting smashed...

2006-05-17 Thread Jay Blanchard
[snip]
I have a site that is getting 30K+ traffic daily and it is smashing
mySQL -
any ideas on what to do to make the mysql connections more efficient, or
anything in general. No bandwidth issue here, just the server getting
killed.
[/snip]

Without seeing any code or table information my bet would be that none
of your tables are indexed properly. 

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



RE: [PHP] Re : a searching problem in lists

2006-05-17 Thread Jim Moseby
 
 Oops, sorry for my last mail. Not the good mailing-list :-)
 

Au contraire.  This *IS* the good mailing list.  Just not the *right* one.
;-)

JM

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



Re: [PHP] PHP and mySQL getting smashed...

2006-05-17 Thread Alister Bulman

On 17/05/06, Dave Goodchild [EMAIL PROTECTED] wrote:

I have a site that is getting 30K+ traffic daily and it is smashing mySQL -
 any ideas on what to do to make the mysql connections more efficient, or
 anything in general. No bandwidth issue here, just the server getting
 killed.

 ...I may be wrong but using persistent connections (mysql_pconnect) may
help. Also, optimise your tables and use the explain command to see how
efficient your queries are.


And caching things that don't need to looked up form the database
right now.  Even the fastest server in the world would wilt under a
slashdotting, if it had to do a dozen big queries for every page
display.  Meanwhile a Pentium3 with a decent network can serve
hundreds of requests a second of a few static pages.

Alister

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



Re: [PHP] Regex Help for URL's [ANSWER]

2006-05-17 Thread Edward Vermillion


On May 16, 2006, at 7:53 PM, Chrome wrote:


-Original Message-
From: Robert Samuel White [mailto:[EMAIL PROTECTED]
Sent: 17 May 2006 01:42
To: php-general@lists.php.net
Subject: RE: [PHP] Regex Help for URL's [ANSWER]



That's what I was doing.  I was parsing A:HREF, IMG:SRC, etc.

But when I implemented a new feature on my network, where you  
could click

on
a row and have it take you to another domain, I need a better  
solution.


Go to http://www.enetwizard.ws and it might make more sense.

All the links on the left have an ONCLICK=location.href = ''  
attribute in

the TR tag.

This solution allowed me to make sure those links included the  
session

information, just like the A:HREF links do.

It also had the advantage of updating the links in my CSS.


O that breaks accessibility standards! Compliment the  
'onclick's with

onkeydown at least :)

But still you get a solid onclick=... scenario

If these are visible in the source then they are fairly easy to  
pick out


Though you may need more than 1 regex ;)

My complaint here is, don't break accessibility :)



And don't forget the folks who have javascript turned off or are  
using text based browsers too.


Ed

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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Ron Clark

Mark Sargent wrote:

Chris wrote:


Big security issue - don't do it.

ps au | grep apache
root   /usr/sbin/apache
htdocs /usr/sbin/apache
htdocs /usr/sbin/apache

My apache is running as htdocs. So as root create a temp folder and 
chown it to htdocs:


mkdir /my_temp_dir
chown htdocs. /my_temp_dir


Hi All,

ok, created dir, added htdocs user/group and changed ownership of dir to 
them. Thing I'm gettin is, every time I make an adjustment to either 
php.ini or httpd.conf, and do a restart, I keep getting a 404 error for 
all pages. Which only corrects when doing a reboot of the box. This was 
happening before I just followed your last steps. Thoughts? Cheers.


Mark Sargent.



I thought you said in earlier email that your apache was running as user 
daemon. The tmp directory has to be owned by the user running apache. If 
you want to run apache as user apache group apache then you will have to 
edit httpd.conf and change the User and Group directives. Otherwise 
chown chgrp the tmp directory to the user/group that is listed in the 
httpd.conf file.

--
Ron Clark
System Administrator
Armstrong Atlantic State University
11935 Abercorn Street
Savannah, Ga 31419
Phone: 912 961 3234
Fax: 912 927 5353

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



Re: [PHP] Security Concerns with Uploaded Images:

2006-05-17 Thread Rory Browne

On 5/16/06, Richard Lynch [EMAIL PROTECTED] wrote:


On Mon, May 15, 2006 1:58 am, Jason Wong wrote:
 2) the uploaded file is a script (perl/php/python/etc)

 In the case of (2), if the script relies on its shebang line to
 execute

Not necessarily -- What if I upload an image file named
badscript.php and then I surf to it, after it's in your /images
directory?



When using the php apache module, from a OS permissions, the Server reads as
opposed to executes php code. .php files don't generally need to be
executable IIRC.

Game Over



If you want Shifflet's view, just go to http://phpsec.org

--
Like Music?
http://l-i-e.com/artists.htm

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




RE: [PHP] Security Concerns with Uploaded Images:

2006-05-17 Thread George Pitcher
 On Mon, May 15, 2006 1:58 am, Jason Wong wrote:
  2) the uploaded file is a script (perl/php/python/etc)

  In the case of (2), if the script relies on its shebang line to
  execute

 Not necessarily -- What if I upload an image file named
 badscript.php and then I surf to it, after it's in your /images
 directory?

On my sites, I know aht file extensions that I will allow, so block (by
script) anything that doesn't match - in my case, that's '.tif' and '.pdf'.

George

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



[PHP] Ajax (xmlHttpRequest) and session_start() problem.

2006-05-17 Thread Mathijs

I Have an very strange problem.

When i execute an very simple Ajax request to an PHP script wich just 
print one line and i put an sleep(20) infront of it, it works perfectly 
when i refresh the page.


BUT..
When i put session_start() at the top, i can't refresh the page anymore.
It won't refresh untill the server responed.

When i remove the session_start(), i can refresh anytime i want.

Is this a know problem?
Does someone knows an solution?

Thx for the help.

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



Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.

2006-05-17 Thread Robert Cummings
On Wed, 2006-05-17 at 10:11, Mathijs wrote:
 I Have an very strange problem.
 
 When i execute an very simple Ajax request to an PHP script wich just 
 print one line and i put an sleep(20) infront of it, it works perfectly 
 when i refresh the page.
 
 BUT..
 When i put session_start() at the top, i can't refresh the page anymore.
 It won't refresh untill the server responed.
 
 When i remove the session_start(), i can refresh anytime i want.
 
 Is this a know problem?
 Does someone knows an solution?

PHP sessions use locking to avoid race conditions. So you sleep for 20
seconds keeps the lock for just as long, this has the effect of blocking
all other scripts for the same session. To avoid this, grab the session
data you need, and close the session as fast as possible. Additionally,
it's probably a very bad idea to keep the web server waiting for 20
seconds for no good reason. Why not have your javascript do the waiting?

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] PHP and mySQL getting smashed...

2006-05-17 Thread Jochem Maas

Jay Blanchard wrote:

[snip]
I have a site that is getting 30K+ traffic daily and it is smashing
mySQL -
any ideas on what to do to make the mysql connections more efficient, or
anything in general. No bandwidth issue here, just the server getting
killed.
[/snip]

Without seeing any code or table information my bet would be that none
of your tables are indexed properly. 


and/or that the OP is using some killing JOINS in his queries - these
often have a detremental effect regardless of indexes.





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



Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.

2006-05-17 Thread Mathijs

Robert Cummings wrote:

On Wed, 2006-05-17 at 10:11, Mathijs wrote:

I Have an very strange problem.

When i execute an very simple Ajax request to an PHP script wich just 
print one line and i put an sleep(20) infront of it, it works perfectly 
when i refresh the page.


BUT..
When i put session_start() at the top, i can't refresh the page anymore.
It won't refresh untill the server responed.

When i remove the session_start(), i can refresh anytime i want.

Is this a know problem?
Does someone knows an solution?


PHP sessions use locking to avoid race conditions. So you sleep for 20
seconds keeps the lock for just as long, this has the effect of blocking
all other scripts for the same session. To avoid this, grab the session
data you need, and close the session as fast as possible. Additionally,
it's probably a very bad idea to keep the web server waiting for 20
seconds for no good reason. Why not have your javascript do the waiting?

Cheers,
Rob.


This whas just an test example i talked about.
irl, i have an script that does an search on the server for texts in files.

This search goes through an ajax request.
The page that is requested uses $_SESSION.
Therefore i need session_start().

This search can take a while, and if i want to refresh the page, because 
i want to have an other search or whatever, i just can't.
This because, for some reason, when session_start() gets called, it 
locks the refreshing capeabileties of the browser.


Also, you say to close the session, mabye a stupid question, but how

If you need more info, just ask :)..

Thx for the quick reply :).

Kind Regards,

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



Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.

2006-05-17 Thread Thomas Munz
session_write_close();

Ex:

session_start();
$asdf = $_SESSION; //-- get all datas
session_write_close(); //-- close session

on Wednesday 17 May 2006 16:36, Mathijs wrote:
 Robert Cummings wrote:
  On Wed, 2006-05-17 at 10:11, Mathijs wrote:
  I Have an very strange problem.
 
  When i execute an very simple Ajax request to an PHP script wich just
  print one line and i put an sleep(20) infront of it, it works perfectly
  when i refresh the page.
 
  BUT..
  When i put session_start() at the top, i can't refresh the page anymore.
  It won't refresh untill the server responed.
 
  When i remove the session_start(), i can refresh anytime i want.
 
  Is this a know problem?
  Does someone knows an solution?
 
  PHP sessions use locking to avoid race conditions. So you sleep for 20
  seconds keeps the lock for just as long, this has the effect of blocking
  all other scripts for the same session. To avoid this, grab the session
  data you need, and close the session as fast as possible. Additionally,
  it's probably a very bad idea to keep the web server waiting for 20
  seconds for no good reason. Why not have your javascript do the waiting?
 
  Cheers,
  Rob.

 This whas just an test example i talked about.
 irl, i have an script that does an search on the server for texts in files.

 This search goes through an ajax request.
 The page that is requested uses $_SESSION.
 Therefore i need session_start().

 This search can take a while, and if i want to refresh the page, because
 i want to have an other search or whatever, i just can't.
 This because, for some reason, when session_start() gets called, it
 locks the refreshing capeabileties of the browser.

 Also, you say to close the session, mabye a stupid question, but how

 If you need more info, just ask :)..

 Thx for the quick reply :).

 Kind Regards,

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



[PHP] Warning: chmod(): Operation not permitted ?

2006-05-17 Thread tedd

Hi (please insert your preference):

This should be simple, but I'm having problems.

I have a program that uploads an image file and then tries to set the 
permissions for the image (to be altered later). However, I get a 
Warning: chmod(): Operation not permitted error when trying to set 
the permission, what gives? If my program created the file, shouldn't 
it have permission to set the files permissions?


What am I not understanding?

Thanks.

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] Warning: chmod(): Operation not permitted ?

2006-05-17 Thread Jochem Maas

tedd wrote:

Hi GANG:


:-)



This should be simple, but I'm having problems.

I have a program that uploads an image file and then tries to set the 
permissions for the image (to be altered later). However, I get a 
Warning: chmod(): Operation not permitted error when trying to set the 
permission, what gives? If my program created the file, shouldn't it 
have permission to set the files permissions?


chances are that the file is created as user nobody, your not nobody ;-),
ergo you can't chmod it ... can't remember the last time I didn't have root
access to configure/fuck (you pick) the server the way I wanted it.

I'm sure someone here knows exactly how to sort this issue without editing the
httpd.conf.



What am I not understanding?

Thanks.

tedd


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



Re: [PHP] Warning: chmod(): Operation not permitted ?

2006-05-17 Thread John Nichel

tedd wrote:

Hi (please insert your preference):

This should be simple, but I'm having problems.

I have a program that uploads an image file and then tries to set the 
permissions for the image (to be altered later). However, I get a 
Warning: chmod(): Operation not permitted error when trying to set the 
permission, what gives? If my program created the file, shouldn't it 
have permission to set the files permissions?


What am I not understanding?


Without seeing code, permissions of the directories, what sticky bits 
might or might not be set, etc., you could not be understanding many 
thingsor just onewho knows.


http://www.google.com/search?q=php+%22Warning%3A+chmod%28%29%3A+Operation+not+permitted%22btnG=Search

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Security Concerns with Uploaded Images:

2006-05-17 Thread Jason Wong
On Tuesday 16 May 2006 07:45, Richard Lynch wrote:
 On Mon, May 15, 2006 1:58 am, Jason Wong wrote:
  2) the uploaded file is a script (perl/php/python/etc)
 
  In the case of (2), if the script relies on its shebang line to
  execute

 Not necessarily -- What if I upload an image file named
 badscript.php and then I surf to it, after it's in your /images
 directory?

I was assuming that any developer who allowed image files to be named 
*.php would be hung, drawn  quartered and shot a few times for good 
measure :)

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
New Year Resolution: Ignore top posted posts

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



Re: [PHP] Ajax (xmlHttpRequest) and session_start() problem.

2006-05-17 Thread Mathijs

Thank you very much :D.

Ill just create an class which will handle this :).
It works like a charm..

Thx.


Thomas Munz wrote:

session_write_close();

Ex:

session_start();
$asdf = $_SESSION; //-- get all datas
session_write_close(); //-- close session

on Wednesday 17 May 2006 16:36, Mathijs wrote:

Robert Cummings wrote:

On Wed, 2006-05-17 at 10:11, Mathijs wrote:

I Have an very strange problem.

When i execute an very simple Ajax request to an PHP script wich just
print one line and i put an sleep(20) infront of it, it works perfectly
when i refresh the page.

BUT..
When i put session_start() at the top, i can't refresh the page anymore.
It won't refresh untill the server responed.

When i remove the session_start(), i can refresh anytime i want.

Is this a know problem?
Does someone knows an solution?

PHP sessions use locking to avoid race conditions. So you sleep for 20
seconds keeps the lock for just as long, this has the effect of blocking
all other scripts for the same session. To avoid this, grab the session
data you need, and close the session as fast as possible. Additionally,
it's probably a very bad idea to keep the web server waiting for 20
seconds for no good reason. Why not have your javascript do the waiting?

Cheers,
Rob.

This whas just an test example i talked about.
irl, i have an script that does an search on the server for texts in files.

This search goes through an ajax request.
The page that is requested uses $_SESSION.
Therefore i need session_start().

This search can take a while, and if i want to refresh the page, because
i want to have an other search or whatever, i just can't.
This because, for some reason, when session_start() gets called, it
locks the refreshing capeabileties of the browser.

Also, you say to close the session, mabye a stupid question, but how

If you need more info, just ask :)..

Thx for the quick reply :).

Kind Regards,



---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 0620-0, 05/15/2006
Tested on: 5/17/2006 6:37:16 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com






---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0620-0, 05/15/2006
Tested on: 5/17/2006 6:38:04 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com

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



Re: [PHP] Security Concerns with Uploaded Images:

2006-05-17 Thread Richard Collyer

Richard Lynch wrote:

On Mon, May 15, 2006 1:58 am, Jason Wong wrote:

2) the uploaded file is a script (perl/php/python/etc)



In the case of (2), if the script relies on its shebang line to
execute


Not necessarily -- What if I upload an image file named
badscript.php and then I surf to it, after it's in your /images
directory?


Couldn't you just use the apache directory option to make sure that php 
can't be executed from the /images directory... wonder if that is possible.


Cheers
Richard

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



Re: [PHP] Regex Help for URL's

2006-05-17 Thread Kevin Waterson
This one time, at band camp, Robert Samuel White [EMAIL PROTECTED] wrote:

 Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
 programming for 20 years (since I was 11 years old) so I'm not a slacker
 when it comes to learning new things, however, I have always found regular
 expressions to be extremely difficult.  Someone here might have the answer I
 need, and if so, I'd appreciate a response.  If you don't know the answer,
 don't reply.  Simple enough, don't you think?

Sorry, I missed most of this...
From what I gather you wish to extract urls from text?
if so..
function getLinks($string){
  // regex to get the links
  preg_match_all(|http:?([^\' ]+)|i, $string, $arrayoflinks);
  return $arrayoflinks;
}

Also check out this on line tutorial for regex geared towards PHP
http://phpro.org/tutorials/Introduction-to-PHP-Regular-Expressions.html

Kind regards
Kevin

-- 
Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote.

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



[PHP] Handling Large Check Box Data

2006-05-17 Thread Rahul S. Johari
Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which will
also provide the same 25 - 30 check boxes which define the search criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and
if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that
and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks, 

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Brad Bonkoski
Well, listing all the values in a comma separated list in the DB would 
be fairly simple to parse, check out:

http://www.php.net/manual/en/function.explode.php

As far as what is better depends on many things...
1). Maintaining the code, might be better to have each check box have 
its own field, will certainly cut down on development/debugging.
2). Performance...don't know if it is faster for PHP to parse through a 
comma separated list or parse through a larger DB record set. I guess if 
this is really important to you, you might want to attempt both ways to 
see on performance.


-Brad



Rahul S. Johari wrote:


Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which will
also provide the same 25 - 30 check boxes which define the search criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and
if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that
and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks, 


Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com


 



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



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Martin Alterisio

2006/5/17, Rahul S. Johari [EMAIL PROTECTED]:


Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information
which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which
will
also provide the same 25 - 30 check boxes which define the search
criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and

if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty
And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that

and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks,

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com





You should consider using MySQL special column type SET:

http://dev.mysql.com/doc/refman/5.1/en/set.html

Or encoding each checkbox status as a binary bit in an integer (which is
what MySQL does when using a SET column).


Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Jochem Maas

Martin Alterisio wrote:

2006/5/17, Rahul S. Johari [EMAIL PROTECTED]:



...







You should consider using MySQL special column type SET:

http://dev.mysql.com/doc/refman/5.1/en/set.html

Or encoding each checkbox status as a binary bit in an integer 


I was going to suggest this also- if nothing else it would be a cool
way to learn a bit (pun intended :-) about bitmask/bitfields/bitwise-operations.





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



Re: [PHP] Fast search

2006-05-17 Thread Robin Vickery

On 17/05/06, René Fournier [EMAIL PROTECTED] wrote:

Looking for suggestions on the most compute-efficient way to search
variable-length strings (~200 characters) for the occurrence of one
of about 100 possible needles. In other words:






$needles = array ( 1 = Hello Jim , 2 = Yellow Banana , 3 =
Red Car, ... etc  (100 elements)

$haystack = Once upon a time there was a programming language that
everyone loved. Its name was PHP, and the people that worked with it
also liked Yellow Bananas. One day...;



What version of php?

If you're using php5  then you could do:

?php
  $count = 0;
  str_replace($needles, '', $haystack, $count);
  if ($count)  { /* there was a match */ }
?

-robin

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



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Kevin Murphy
I did something similar recently. Basically I have one MySQL field to  
handle several dozen checkboxes, my situation though was where the  
checkboxes are numerically sequential though so I am not sure if this  
helps. I also had only a couple hours to do this from start to finish  
so I am sure there is a better way, but maybe this helps.


 I wrote a function that generates the row of checkboxes, then a  
function that combines them all into one field and so the status of  
every checkbox is in one field.



Function generates the checkboxes and checks in the array if that  
checkbox is checked or not.


function row_generator($row,$number,$array)
{
echo \ntr;
echo \n\tth align=\center\ valign=\top\Row $row/th;

$i = 1;
while ($i = $number)
{

if ($i  10)
{   $row_number = {$row}-0{$i}; }
else
{   $row_number = {$row}-{$i};  }

echo \n\ttd align=\center\ valign=\top\;
		echo input type=\checkbox\ name=\$row_number\ id=\$row_number 
\;


if (strstr($array,$row_number) === FALSE)
{   echo ;  }
else
{   echo  CHECKED;  }

echo ;
echo br;
echo $i;
echo /td;
$i++;

}
echo \n/tr;
}

In use:

$seats = $row['seats'];
row_generator(A,23,$seats);

Collect the posted Data and then later this gets input into a database

$poster_A = ;
$i = 1;
while ($i = 30)
{
if ($i  10) 
{   $r = 0{$i}; }
else
{   $r = $i;}
if (isset($_POST[A-$r]))
{   $poster_A .= A-$r;  
$poster_A .= :; }
$i++;
}

$seats = ({$poster_A}{$poster_B} etc);
$query = UPDATE seating_chart SET
seats = '$seats'
WHERE season = '2006';


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On May 17, 2006, at 11:21 AM, Rahul S. Johari wrote:


Ave,

I’m a little confused as to what’s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of  
25 – 30
Check Boxes, each of which asks the user for some kind of  
information which

the user can check or leave unchecked.
The information each Check Box collects will also appear in the  
“Listing”

for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users  
which will
also provide the same 25 - 30 check boxes which define the search  
criteria.

I’m not sure what’s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL  
database, and
if the check box is checked, the data goes into the corresponding  
field...
And similarly listing the data from the field if field is non- 
empty And

similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think  
about
creating a single field and storing the data from each ‘checked’  
check box
as comma separated values in the single field. I’m not sure how to  
do that
and if that’s the best way But even if I can, I’m not sure how  
to get
the data to display separately out of that field in the Listings  
view and

more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks,

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com



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



Re: [PHP] Fast search

2006-05-17 Thread Evan Priestley
You can make a pretty effective time/memory tradeoff -- particularly  
if your array of patterns is relatively fixed -- but unless you re- 
implement this in C, it will probably be slower than a brute force  
approach with the str* functions unless you are searching for a  
fairly huge number of needles.


Below, I build a tree of pattern matches, which you navigate branch- 
by-branch by using successive letters of the pattern. So, after the  
tree is built, the index $tree[ 'h' ][ 'a' ][ 't' ] exists and has  
the value `true'. To search the string, you push cursors onto a  
stack, advance them as you advance through the string, and destroy  
them when they hit a dead end.


This has a worst case of O( N^2 ) (on the length of the string),  
which happens when you search for patterns like a  
and b in the string h. The  
average case for random or typical strings should be very close to O 
( N ). Critically, search time is a function only of the length of  
the string, not of the number of patterns. Memory usage is also only  
a function of the size of the character set and the length of the  
longest pattern, not of the total number of patterns.


This particular implementation has some nice side-effects; uncomment  
the var_dump() line and note how 'pirate' and 'firm' have been  
optimized out of the tree in favor of 'pir' and 'fir'.


Evan

?php

$pattern = array(
 'hat'
,'hut'
,'blue dog'
,'blue cat'
,'pirate'
,'pir'
,'fir'
,'firm'
);

$tree = array( );
foreach( $pattern as $str ) {
$len = strlen( $str );
$cursor = $tree;
for( $ii = 0; $ii  $len; $ii++ ) {
if( !isset( $cursor[ $str[ $ii ] ] ) ) {
$cursor[ $str[ $ii ] ] = array( );
}
$cursor = $cursor[ $str[ $ii ] ];
if( $cursor === true ) break;
}
$cursor = true;
}

/*  var_dump 
( $tree );  */


$corpus = 'lorem ipsum dolor sur amet pi blue do he hi h fipir  
slog';

$clen   = strlen( $corpus );

$stack  = array( );
for( $ii = 0; $ii  $clen; $ii++ ) {
$c = $corpus[ $ii ];
foreach( $stack as $k = $_ ) {
if( isset( $stack[ $k ][ $c ] ) ) {
if( $stack[ $k ][ $c ] === true ) {
die( 'Matched at position '.$ii );
}
$stack[ $k ] = $stack[ $k ][ $c ];
}
else {
unset( $stack[ $k ] );
}
}
if( isset( $tree[ $c ] ) ) {
$stack[] = $tree[ $c ];
}
}
die( 'Did not find a match.' );

?



On May 17, 2006, at 12:37 PM, René Fournier wrote:

Looking for suggestions on the most compute-efficient way to search  
variable-length strings (~200 characters) for the occurrence of one  
of about 100 possible needles. In other words:




$needles = array ( 1 = Hello Jim , 2 = Yellow Banana , 3 =  
Red Car, ... etc  (100 elements)


$haystack = Once upon a time there was a programming language that  
everyone loved. Its name was PHP, and the people that worked with  
it also liked Yellow Bananas. One day...;




Now perhaps I'm blind, but I can't see an obvious string or array  
function that simply allows you to use an array as a needle while  
searching a string haystack. What I'm really looking for is  
something like the reverse of in_array.


The obvious thing would be to loop through the needles and run  
substr_count on the haystack... But is there a faster way?


...Rene

--
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] Simple XML array count??

2006-05-17 Thread Jay Paulson
I'm using SimpleXML to go through a Google search result and I'm not quite
understanding something.  The variable $xml-RES-R is an array of 9 items
and each item is an object containing information (see var dump below).  So
when I try to do count($xml-RES-R); it returns a number or 1 instead a
number of 10.  Also, when I do a print_r($xml-RES-R); all I get is a dump
of $xml-RES-R[0] and not the rest of the array.  I'm not quite sure what
is going on?  I'm using PHP 5.0.4 maybe there's a bug?

SimpleXMLElement Object
(
[TM] = 0.081574
[Q] = benefits
[PARAM] = Array
(
[0] = SimpleXMLElement Object
(
)

[1] = SimpleXMLElement Object
(
)

[2] = SimpleXMLElement Object
(
)

[3] = SimpleXMLElement Object
(
)

[4] = SimpleXMLElement Object
(
)

[5] = SimpleXMLElement Object
(
)

[6] = SimpleXMLElement Object
(
)

[7] = SimpleXMLElement Object
(
)

[8] = SimpleXMLElement Object
(
)

)

[RES] = SimpleXMLElement Object
(
[M] = 1830
[FI] = SimpleXMLElement Object
(
)

[NB] = SimpleXMLElement Object
(
[NU] =
/search?q=benefitssite=default_collectionhl=enlr=ie=UTF-8output=xml_no_
dtdclient=default_frontendaccess=psort=date:D:L:d1start=10sa=N
)

[R] = Array
(
[0] = SimpleXMLElement Object
(
[U] = http://benefits/
[UD] = http://benefits/
[UE] = http://benefits/
[T] = bBenefits/b
[RK] = 10
[FS] = SimpleXMLElement Object
(
)

[S] = Home, bBenefits/b Forms Jobs Training
Locations, Who We Are E-Info Publications EVAbr Team Websites. b.../b
2006 bBenefits/b Vote. bBenefits/b Links. bBenefits/b Websites.
b.../b  
[LANG] = en
[HAS] = SimpleXMLElement Object
(
[L] = SimpleXMLElement Object
(
)

[C] = SimpleXMLElement Object
(
)

)

)

[1] = SimpleXMLElement Object
(
[U] = http://benefits/benefits_websites.html
[UD] = http://benefits/benefits_websites.html
[UE] = http://benefits/benefits_websites.html
[T] = bBenefits/b

[RK] = 9
[CRAWLDATE] =  17 May 2006
[FS] = SimpleXMLElement Object
(
)

[S] = Home, bBenefits/b Forms Jobs Training
Locations, Who We Are E-Info Publicationsbr EVA Team Websites.
bBenefits/b Websites.  b.../b
[LANG] = en
[HAS] = SimpleXMLElement Object
(
[L] = SimpleXMLElement Object
(
)

[C] = SimpleXMLElement Object
(
)

)

[HN] = /benefits
)

[2] = SimpleXMLElement Object
(
[U] = http://www..com/jobs//benefits.html
[UD] = http://www..com/jobs//benefits.html
[UE] = http://www..com/jobs//benefits.html
[T] = Whole Foods : Jobs : North Atlantic
Region Career Opportunities
[RK] = 10
[CRAWLDATE] =  15 May 2006
[FS] = SimpleXMLElement Object
(
)

[S] = b.../b  bBenefits/b Summary.
b.../b The bBenefits/b of a Unique Culture. Atbr  b.../b
success. Medical Care bBenefits/b. Available after b.../b
[LANG] = 

Re: [PHP] Fast search

2006-05-17 Thread Robert Cummings
On Wed, 2006-05-17 at 16:38, Robin Vickery wrote:
 On 17/05/06, René Fournier [EMAIL PROTECTED] wrote:
  Looking for suggestions on the most compute-efficient way to search
  variable-length strings (~200 characters) for the occurrence of one
  of about 100 possible needles. In other words:
 
 
 
 
  $needles = array ( 1 = Hello Jim , 2 = Yellow Banana , 3 =
  Red Car, ... etc  (100 elements)
 
  $haystack = Once upon a time there was a programming language that
  everyone loved. Its name was PHP, and the people that worked with it
  also liked Yellow Bananas. One day...;
 
 
 What version of php?
 
 If you're using php5  then you could do:
 
 ?php
$count = 0;
str_replace($needles, '', $haystack, $count);
if ($count)  { /* there was a match */ }
 ?

Surely you meant strpos( $haystack, $needle ) ???

Incidentally do you need to match on words beginnings or endings? For
instance should 'put' match all of the following:

I put the apple core in the compost.
Someone always puts the fire out.
The car sputtered and died.

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



[PHP] Getting rid of Web page has expired (POSTDATA error)

2006-05-17 Thread Nicolas Verhaeghe
I am having an issue with certain pages preventing the user from going back
to the previous page.

The message given by Firefox is: The page you are trying to view contains
PSTDATA that has expired from cache.

This happens in the case of an HTML form using the POST method but also a
query object in the URL.

In this case: index.php?id=shopping_cart in my URL, along with a bunch of
form data you carry from page to page in a shopping cart (quantities, what
to remove, addresses, payment info, etc...)

Is this due to the fact that I am mixing POST and query objects or is it
something else?

I already tried adding the following but it does not help:

header(Cache-Control: no-store, no-cache, must-revalidate);
header(Cache-Control: post-check=0, pre-check=0, false);
header(Pragma: no-cache);

Thanks for your help!

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



Re: [PHP] Warning: chmod(): Operation not permitted ?

2006-05-17 Thread tedd

At 11:18 AM -0400 5/17/06, John Nichel wrote:

tedd wrote:

Hi (please insert your preference):

This should be simple, but I'm having problems.

I have a program that uploads an image file and then tries to set 
the permissions for the image (to be altered later). However, I get 
a Warning: chmod(): Operation not permitted error when trying to 
set the permission, what gives? If my program created the file, 
shouldn't it have permission to set the files permissions?


What am I not understanding?


Without seeing code, permissions of the directories, what sticky 
bits might or might not be set, etc., you could not be understanding 
many thingsor just onewho knows.


I read all of your Google links, but no help. Just another example of 
how Google is not the answer.


In any event, my code is pretty simple, just:

chmod($url, 0755);  //where $url is the file I want to change.

The error I receive is noted above in the subject line.

The permissions of the directories vary, but the folder that has the 
file I want to change permissions is currently set at 0777.


In doing a lstat() of both the parent program that created the file 
and the child file shows that they both have the identical uid and 
gid (i.e., the same user and group id's).


Now, everything I've read, says:

chmod() changes the permission of the specified file with the following caveat.

chmod() can only change the permissions of files that are owned by 
the user running the command. In most cases, this is the user that 
the web server runs on.


That confuses me, because who's the user here? Is it just the system 
administrator or the application?


And if it is just the system administrator, then can't the system 
admin change anything he/she wants anyway? What's the point of having 
uid and gid's if a program can't change the permissions of a sibling 
file?


I have tons of references as to what php filesystem functions are 
available, but I need a good reference as to what permissions are and 
how they actually can be changed in php -- does anyone have one a 
good reference OR care to explain?


As it is now, I know how ride the horse, but I can't get the gate open.

Thanks.

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] Warning: chmod(): Operation not permitted ?

2006-05-17 Thread Brady Mitchell
 chmod() can only change the permissions of files that are owned by 
 the user running the command. In most cases, this is the user that 
 the web server runs on.
 
 That confuses me, because who's the user here? Is it just the system 
 administrator or the application?

This is the user that Apache (or whatever webserver) is running as.  If
you're using Apache, look at your httpd.conf file to find out who that
user is.  If you're creating files successfully, you can just look at
the owner of that file to find out who it is.

Is safe_mode enabled?

From the manual (http://us3.php.net/chmod):

Note:  When safe mode is enabled, PHP checks whether the files or
directories you are about to operate on have the same UID (owner) as the
script that is being executed. In addition, you cannot set the SUID,
SGID and sticky bits.

So, if you're running in safe mode, the php file, and the files that you
need to modify have to be owned by the same user.

Say you have process.php which is operating on the uploaded files, and
it is owned by the jondoe user.  The files that you wanted to chmod()
would also have to be owned by jondoe, which is probably not the case.
Apache is often run under the apache, www, or nobody user.

HTH,

Brady

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



Re: [PHP] Converting characters

2006-05-17 Thread Ligaya Turmelle

Jonas Rosling wrote:

Hi,
the PHP newbie is here again asking questions.
Is there anyway in PHP to convert none international characters so the are
displayed correct?
In my case I have lots of data in the database with å,ä and ö.

Thanks // Jonas


Have you looked at the mbstring or iconv extensions?

--

life is a game... so have fun.

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

[PHP] Need help calling PHP page from another server.

2006-05-17 Thread Robert Filipovich

I am using a chat program and trying to call the status page from another
server and the graphic that the page returns does not show up.

It works if you are calling from the webserver that the chat program is
working so i feel it is some type of config problem or security issue.

http://www.hidho.com/chattest.htm is the page that uses the code

a href=javascript:pophelp('
http://chat.siuprem.com/siupchat/client.php',500,500)img src=
http://chat.siuprem.com/siupchat/statusimage.php;/a and it works on
http://chat.siuprem.com/siupchat/chattest.htm which is the windows IIS
sesrver where PHP is running.

Any help would be great.

/Robert


[PHP] Add Multiple Items, Qty to Cart from html form

2006-05-17 Thread Andras Kende

Hello,

I trying to add multiple items to a shopping cart with selectable quantity 
and price form text field like..


apple   : qty: [__]  price: [__]
orange : qty: [__]  price: [__]
Add Items to Cart


I could add multiple items with checkboxes but without selecting quantity 
and price..


if (isset($_POST['itemschecked'])) {
foreach($_POST['itemschecked'] as $itemschecked = $checkeditems ){
AddItem($checkeditems, 1);
}

Any help is appreciated..

Thanks,

Andras 


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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Chris

Mark Sargent wrote:

Chris wrote:


Sounds like you're using the wrong script to restart apache.

What command are you using?


service httpd restart


Rebooting will most likely pick up the /etc/init.d/apache or 
/etc/init.d/httpd script.


Have this in /etc/rc.local on Fedora 5,

startApache=/usr/local/apache2/bin/apachectl
if [ -f $startApache ] ; then
$startApache start
fi

and I see that I have left off start at the end of startApache.


There's your problem.

service httpd restart

will most likely restart /usr/sbin/httpd.

That's not the same as /usr/local/apache2

Remove the rpm to save confusion next time:

rpm -e httpd

then when you need to restart, always use the 
/usr/local/apache2/bin/apachectl file.


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

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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Mark Sargent

Chris wrote:

There's your problem.

service httpd restart

will most likely restart /usr/sbin/httpd.

That's not the same as /usr/local/apache2

Remove the rpm to save confusion next time:

rpm -e httpd

then when you need to restart, always use the 
/usr/local/apache2/bin/apachectl file.

Hi All,

weird, as I distinctly left out installing any type of servers when 
initially installing FC5.  Cheers.


Mark Sargent

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



Re: [PHP] 404 After Setting session.save_path to /tmp

2006-05-17 Thread Chris

Mark Sargent wrote:

Chris wrote:


There's your problem.

service httpd restart

will most likely restart /usr/sbin/httpd.

That's not the same as /usr/local/apache2

Remove the rpm to save confusion next time:

rpm -e httpd

then when you need to restart, always use the 
/usr/local/apache2/bin/apachectl file.


Hi All,

weird, as I distinctly left out installing any type of servers when 
initially installing FC5.  Cheers.


In my experience redhat and fedora don't really listen to what you want 
properly. What the hell does pcmcia have to do with a server installation?


You need to check it each time you install.

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

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



Re: [PHP] Add Multiple Items, Qty to Cart from html form

2006-05-17 Thread Wolf
Andras,

input type=hidden name=item[] value=applesApples input type=text
name=qty[] value=0 input type=text name=price[] value=0

Will get you where you need to go on the HTML side of things, then on
the back end you need to process each array.  By setting a default value
of 0 for the qty, you force users to change the values, but you also
keep your arrays intact and easier (IMHO) to deal with.

Wolf

Andras Kende wrote:
 Hello,
 
 I trying to add multiple items to a shopping cart with selectable
 quantity and price form text field like..
 
 apple   : qty: [__]  price: [__]
 orange : qty: [__]  price: [__]
 Add Items to Cart
 
 
 I could add multiple items with checkboxes but without selecting
 quantity and price..
 
 if (isset($_POST['itemschecked'])) {
 foreach($_POST['itemschecked'] as $itemschecked = $checkeditems ){
 AddItem($checkeditems, 1);
 }
 
 Any help is appreciated..
 
 Thanks,
 
 Andras

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