[PHP] Socket server in PHP

2005-06-23 Thread kioto
Hi all sorry for the ignorance :D.This is my first time with Socket and 
i have

a question for you.I want create a script that run like daemon in background
and listen incoming request.It's possible with socket open a stream to a 
directory

and check any change on this directory ?
I want send notify about the state of directory through e-mail for example:
when a user add  new files or change any data.
Thanks so much and good work to all.

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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread symbulos
Richard Lynch wrote:
 Can you get the usename/password from the other application?

Yes, we have them.

 With it, you can then use http://php.net/curl to simulate the user logging
 in to the other site.

Thanks.
 
 You simply have to convince the other site that your PHP script actually
 *IS* the user logging in, which is seldom very tricky, and is always
 *POSSIBLE* with enough effort.
 
How can be that done? Do you know of any tutorial, example?

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



[PHP] Re: Help recognizing bots?

2005-06-23 Thread JamesBenson

http://www.funender.com/phpBB2/about18577.html








Brian Dunning wrote:

I'm using the following code in an effort to identify bots:

$client = $_SERVER['HTTP_USER_AGENT'];
if(!strpos($client, 'ooglebot')  !strpos($client, 'ahoo')  !strpos 
($client, 'lurp')  !strpos($client, 'msnbot'))

{
(Stuff that I do if it's not a bot)
}

But it doesn't seem to be catching a lot of bot action. Anyone have a  
better list of user agents? (I left off the first letter of some to  
avoid case conflicts.)


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



Re: [PHP] comparing two texts

2005-06-23 Thread Jochem Maas

Robert Cummings wrote:

On Wed, 2005-06-22 at 22:55, Richard Lynch wrote:



...




Well some noobs might think crude works quite well for them :)



Ya want me to do Jenny's work for her for free or what?! :-)



No but it seemed like Jenny did *grin*.


_seemed_ ??? r u kidding :-)

whereas I'll happily spend an hour writing up and contemplating someone
else's problem - I don't have five minutes for people who are expecting to be
spoonfed (go learn ASP and get a support contract, thanks ;-).





The point was that depending on what Jenny wants for output, it could be
pretty easy to compare two strings character by character.

Or it could be incredibly difficult, if you need diff-like capabilities of
recognizing similar lines of text interspersed with radically different
lines of text.

She obviously didn't like the use diff answer, so I gave her the yeast
to roll her own.

'Course, she didn't like that either, but that's hardly my fault.


don't suppose you want to hear a joke about 'womens perogative' do you? ;-)


[shrug]





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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread Jochem Maas

symbulos wrote:

Richard Lynch wrote:


Can you get the usename/password from the other application?



Yes, we have them.



With it, you can then use http://php.net/curl to simulate the user logging
in to the other site.



Thanks.
 


You simply have to convince the other site that your PHP script actually
*IS* the user logging in, which is seldom very tricky, and is always
*POSSIBLE* with enough effort.


 
How can be that done? Do you know of any tutorial, example?


one way is to use the cURL extension. the concept is that your script
pretends to be a browser, using cURL to initiate a HTTP connection (aka
a request) to the ASP server - your request should send the same as your 
browser would if
you had sumbitted a login attempt to the ASP site directly...





come on, you too know how to type stuff into the google search box:

http://www.google.nl/search?q=php+cURLstart=0

fourth hit:
http://www.phpfreaks.com/quickcode/Curl_Abstraction_Class_v1.0/120.php





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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread Rory Browne
Just out of curiousity, does your PHP/MySQL site share a domain name?
By that I mean can your site be accessed by php.commondomain.com, and
theirs asp.commondomain.com, where the commondomain.com part is the
same on your side and theirs?

If not, then your site will not be able to set cookies for their site,
so for the login process you'll probably have to redirect the visitor
to the other site(with login parameters(which may or may not be the
uname/passwd) in the QueryString), for it to set the cookie, which can
then redirect back to your site after the login is complete. This
might be simpler than using cURL even if you're on the same domain.

On 6/23/05, symbulos [EMAIL PROTECTED] wrote:
 Richard Lynch wrote:
  Can you get the usename/password from the other application?
 
 Yes, we have them.
 
  With it, you can then use http://php.net/curl to simulate the user logging
  in to the other site.
 
 Thanks.
 
  You simply have to convince the other site that your PHP script actually
  *IS* the user logging in, which is seldom very tricky, and is always
  *POSSIBLE* with enough effort.
 
 How can be that done? Do you know of any tutorial, example?
 
 --
 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] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread symbulos
Rory Browne wrote:

 Just out of curiousity, does your PHP/MySQL site share a domain name?
 By that I mean can your site be accessed by php.commondomain.com, and
 theirs asp.commondomain.com, where the commondomain.com part is the
 same on your side and theirs?

Unfortunately not.

At the same time, we would rather not pass confidential information, like
username / password using get methods (with variable appended to url). This
is the main problem.

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



Re[2]: [PHP] comparing two texts

2005-06-23 Thread Tom Rogers
Hi,

Thursday, June 23, 2005, 9:42:34 PM, you wrote:
.
.
.

JM whereas I'll happily spend an hour writing up and contemplating someone
JM else's problem - I don't have five minutes for people who are expecting to 
be
JM spoonfed (go learn ASP and get a support contract, thanks ;-).

Perhaps I missed it but could you point out the bit where the original
poster asked to be spoon fed??

-- 
regards,
Tom

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



[PHP] Accessing forms through php

2005-06-23 Thread José Miguel López-Coronado
I have seen how to use cURL to retreive results from a web site after
processing a form. The problem is that I want to simulate completely the
submiting of a form, I mean, I wan to enter the page in the server
instead of retreive the results into my own page. I'm trying to use a
php script to login into a site without having to enter user and pass.
Anyone knows how to do this using cURL or any other option like HEADER
or something like that?

Thanks in advance and best wishes.




Disbase Internet
www.disbase.com
 José Miguel López Coronado

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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread symbulos
Jochem Maas wrote:
 come on, you too know how to type stuff into the google search box:

gorgle? what is that?

 
 http://www.google.nl/search?q=php+cURLstart=0

 fourth hit:
 http://www.phpfreaks.com/quickcode/Curl_Abstraction_Class_v1.0/120.php

I am not sure about it. I did not understand it at all. It is not exactly
well documented.

:-)

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



[PHP] Showing tables (converting from MySQL to Oracle)

2005-06-23 Thread Shane Presley
Hello,

I've recompiled PHP to use Oracle, and been able to run a quick test
script that looks like...

?php
if ($c=OCILogon(user, pw, server)) {
  echo Successfully connected to Oracle.\n;
  OCILogoff($c);
} else {
  $err = OCIError();
  echo Oracle Connect Error  . $err[text];
}
?


So now I'm going through and converting my MySQL code to Oracle.  I've
finished the connect functions, but getting hung up on how to do
queries.  For example the first query wants to SHOW TABLES.  Not sure
how to do this with Oracle calls?

function get_tables($link) {
$tableList = array();
$query = SHOW TABLES;
$result = perform_query($query, $link);
while($row = fetch_array($result)) {
array_push($tableList, $row[0]);
}

return $tableList;
}


function perform_query($query, $link) {
if($link) {
$result = mysql_query($query, $link) or die('Query
failed: ' . mysql_error());
}
else {
die('No DB link');
}

return $result;
}


Thanks!
Shane

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



Re: [PHP] How to convert documents to PDF using PHP

2005-06-23 Thread Rory Browne
What OS are you using?

If you're on Win, then you may be able to do something with COM and a
PDF printer driver(pdfcreator comes to mind - check out theopencd)

If you're not, then you may be able to do something similar with OOo
and UNO, although Python may be a better choice than PHP, since there
is a native Python / UNO module, where as there is no PHP Uno module
afaik. If it _has_ to be PHP based, then perhaps you could make an
extension to interact with UNO in C.

On 6/22/05, Bosky, Dave [EMAIL PROTECTED] wrote:
 I need to find a way to allow users to select multiple files from a list
 and generate a single PDF file from them.
 
 The documents are limited to the following formats: MS Word, MS
 PowerPoint, MS Excel, Plain Text, gif/jpeg images.
 
 
 
 Are there any PHP classes or modules that exist which can tackle this
 tough task?
 
 
 
 Thanks,
 
 Dave
 
 
 
 
 
 HTC Disclaimer:  The information contained in this message may be privileged 
 and confidential and protected from disclosure. If the reader of this message 
 is not the intended recipient, or an employee or agent responsible for 
 delivering this message to the intended recipient, you are hereby notified 
 that any dissemination, distribution or copying of this communication is 
 strictly prohibited.  If you have received this communication in error, 
 please notify us immediately by replying to the message and deleting it from 
 your computer.  Thank you.
 


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



[PHP] setting include_path ini directive at runtime

2005-06-23 Thread blackwater dev
I am calling php from the command line and was wondering how I can set
the include_path of the ini file at run time?  Can I pass in an extra
param to php to set this?

Thanks!

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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread Jochem Maas

symbulos wrote:

Jochem Maas wrote:


come on, you too know how to type stuff into the google search box:



gorgle? what is that?


oh just a little search engine some of us use now and again :-)





http://www.google.nl/search?q=php+cURLstart=0




fourth hit:
http://www.phpfreaks.com/quickcode/Curl_Abstraction_Class_v1.0/120.php



I am not sure about it. I did not understand it at all. It is not exactly
well documented.


story of my life :-)

you can always ask here if you have some specific code that's frying your
brain.



:-)



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



Re: [PHP] setting include_path ini directive at runtime

2005-06-23 Thread John Nichel

blackwater dev wrote:

I am calling php from the command line and was wondering how I can set
the include_path of the ini file at run time?  Can I pass in an extra
param to php to set this?


http://us4.php.net/ini_set
http://us4.php.net/manual/en/ini.php#ini.list

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



RE: [PHP] How to convert documents to PDF using PHP

2005-06-23 Thread Bosky, Dave
I'll be working on a Win 2003 server box. I was reading about a COM
object from verypdf.com. Can you recommend any specific COM objects?

Thanks..

-Original Message-
From: Rory Browne [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 23, 2005 9:13 AM
To: Bosky, Dave
Cc: php-general@lists.php.net
Subject: Re: [PHP] How to convert documents to PDF using PHP

What OS are you using?

If you're on Win, then you may be able to do something with COM and a
PDF printer driver(pdfcreator comes to mind - check out theopencd)

If you're not, then you may be able to do something similar with OOo
and UNO, although Python may be a better choice than PHP, since there
is a native Python / UNO module, where as there is no PHP Uno module
afaik. If it _has_ to be PHP based, then perhaps you could make an
extension to interact with UNO in C.

On 6/22/05, Bosky, Dave [EMAIL PROTECTED] wrote:
 I need to find a way to allow users to select multiple files from a
list
 and generate a single PDF file from them.
 
 The documents are limited to the following formats: MS Word, MS
 PowerPoint, MS Excel, Plain Text, gif/jpeg images.
 
 
 
 Are there any PHP classes or modules that exist which can tackle this
 tough task?
 
 
 
 Thanks,
 
 Dave
 
 
 
 
 
 HTC Disclaimer:  The information contained in this message may be
privileged and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, you
are hereby notified that any dissemination, distribution or copying of
this communication is strictly prohibited.  If you have received this
communication in error, please notify us immediately by replying to the
message and deleting it from your computer.  Thank you.
 


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



[PHP] Re: text areas and line brakes

2005-06-23 Thread Al

Sunny Boy wrote:
if someone writes something in a text box, how would I convert a line 
break in the text area to echo a br /? I think i'll have to get the \n 
and convert it. can anyone tell me?


Thanks.

sunny



I use a technique similar to Lynch's

$value= preg_replace(/(\r\n|\r|\n)/, \n, $value);//this says make \r\n or 
\r or \n a single \n

$value= preg_replace(/\n\n+/, \n\n, $value);//no more than 2 \n 

This fixes the case when some adds excessive newlines   


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



Re: [PHP] Showing tables (converting from MySQL to Oracle)

2005-06-23 Thread Kristen G. Thorson
This is really a question for an Oracle list, but I happen to know of 
the following page which has been helpful to me in the past:


https://gdsg.ngdc.noaa.gov/tiki/tiki-index.php?page=SqlNotes


kgt




Shane Presley wrote:


Hello,

I've recompiled PHP to use Oracle, and been able to run a quick test
script that looks like...

?php
if ($c=OCILogon(user, pw, server)) {
 echo Successfully connected to Oracle.\n;
 OCILogoff($c);
} else {
 $err = OCIError();
 echo Oracle Connect Error  . $err[text];
}
?


So now I'm going through and converting my MySQL code to Oracle.  I've
finished the connect functions, but getting hung up on how to do
queries.  For example the first query wants to SHOW TABLES.  Not sure
how to do this with Oracle calls?

function get_tables($link) {
   $tableList = array();
   $query = SHOW TABLES;
   $result = perform_query($query, $link);
   while($row = fetch_array($result)) {
   array_push($tableList, $row[0]);
   }

   return $tableList;
}


function perform_query($query, $link) {
   if($link) {
   $result = mysql_query($query, $link) or die('Query
failed: ' . mysql_error());
   }
   else {
   die('No DB link');
   }

   return $result;
}


Thanks!
Shane

 



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



[PHP] Strange notation to create object

2005-06-23 Thread Michael Stepanov

Dear all,

Usually, I develop on Perl. But my current task pushes me to start use
PHP. Generally, it's great but sometimes I'm a little bit confused.
For example, recently I've found a strange notation of creation of PHP
objects:

$obj =  new SomeObject();

Can anyone explain me meaning of **?

Thanks in advanced

--
Best regards,
Michael Stepanov
Perl/Linux Developer
Francoudi  Stephanou Ltd
Tel: +357 25-867154
Email: [EMAIL PROTECTED]

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



Re: [PHP] Strange notation to create object

2005-06-23 Thread Rory Browne
It's in the manual.

PHP4
$obj = new SomeObject() would create a SomeObject, and assign it by
value to $obj. $obj would be a copy of the one created. by the new
SomeObject.  makes it assign by reference.

PHP5
In PHP5 Objects are assigned by reference anyway so the  doesn't matter.


On 6/23/05, Michael Stepanov [EMAIL PROTECTED] wrote:
 Dear all,
 
 Usually, I develop on Perl. But my current task pushes me to start use
 PHP. Generally, it's great but sometimes I'm a little bit confused.
 For example, recently I've found a strange notation of creation of PHP
 objects:
 
 $obj =  new SomeObject();
 
 Can anyone explain me meaning of **?
 
 Thanks in advanced
 
 --
 Best regards,
 Michael Stepanov
 Perl/Linux Developer
 Francoudi  Stephanou Ltd
 Tel: +357 25-867154
 Email: [EMAIL PROTECTED]
 
 --
 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] Sorting with french characters

2005-06-23 Thread Mathieu Dumoulin
I've got a little problem with the ksort and sort functions. When i fill 
 this array's keys or the array's data and i sort it, i can't seem to 
get a correct sort order concerning accented french characters.


For example:

Emiss, Erick
Morrison, Phillip
Tatey, Peter
Zachary, Martin
Élement, Marc-André

This is the kind of result i get from Ksort when i put these as keys. 
Notice the Élement, Marc-André at the end? Its supossed to be in the 
Es not at the end.


So i'm wondering how i can make this work now. I can't afford to make a 
STR_REPLACE on all possible accents, i got over a thousand records from 
the database to parse in a fast way and there are at the very least 60 
different accents to replace from the A, E, I, O and U without 
forgetting we have acute, grave, trema, circonflex accents for each 
letter. :S


My guess is there is something in the configuration of my dev server 
that must do this. Can anyone help me?


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



Re: [PHP] Strange notation to create object

2005-06-23 Thread Rory Browne
Try this

?php

$a = 1;
$b = $a; 
$c = $a;

$a = 2;
printf(a=%d, b=%d, c=%d\n, $a, $b, $c);

$c = 3;
printf(a=%d, b=%d, c=%d\n, $a, $b, $c);

?

On 6/23/05, Michael Stepanov [EMAIL PROTECTED] wrote:
 Dear all,
 
 Usually, I develop on Perl. But my current task pushes me to start use
 PHP. Generally, it's great but sometimes I'm a little bit confused.
 For example, recently I've found a strange notation of creation of PHP
 objects:
 
 $obj =  new SomeObject();
 
 Can anyone explain me meaning of **?
 
 Thanks in advanced
 
 --
 Best regards,
 Michael Stepanov
 Perl/Linux Developer
 Francoudi  Stephanou Ltd
 Tel: +357 25-867154
 Email: [EMAIL PROTECTED]
 
 --
 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] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson

Hi,
I checked at http://www.php.net/manual/en/features.file-upload.php and 
all the user notes, and also the PEAR solution for uploading files and I 
still have a couple of questions.


I need to create a form to allow users to upload (and later to delete) 
MS word, excel and jpg files. Through your help I was able to validate 
image files using getimagesize() and have made a nice script to upload 
and rename images.


I cannot see a way to validate or examine Word or Excel files for 
validity (and assume that older word files would validate differently 
from newer ones).


The PEAR http upload script mentioned twice in the user notes at that 
manual page does not *seem* to validate other than denying certain 
extensions like php, php3, etc. I could be wrong of course.


Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to access 
the files via web browser which is the whole point.



So my questions:
1. How do you validate Word and Excel files before upload?

2. How can I make a passthrough from a file above public_html to one 
below it so that people can surf in with a browser and download files 
which have been uploaded by the script?


Thanks in advance,
JJ

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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread John Nichel

Jack Jackson wrote:
snip
Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to access 
the files via web browser which is the whole point.


It shouldn't have to be this way.  The webserver should be configured to 
run as your virtual user, or belong to a group which has write 
permission to that directory, or.I'm getting a bit off track with 
that.  This is something you'll have to take up with your ISP.



So my questions:
1. How do you validate Word and Excel files before upload?


Before?  JavaScript...if JavaScript can even do it (I haven't touched 
the stuff in ages).  After upload, you can check the mime type, but 
that's not foolproof.


2. How can I make a passthrough from a file above public_html to one 
below it so that people can surf in with a browser and download files 
which have been uploaded by the script?


http://us4.php.net/move_uploaded_file

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson


John Nichel wrote:

Jack Jackson wrote:
snip

Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to 
access the files via web browser which is the whole point.



It shouldn't have to be this way.  The webserver should be configured to 
run as your virtual user, or belong to a group which has write 
permission to that directory, or.I'm getting a bit off track with 
that.  This is something you'll have to take up with your ISP.


Will do.




So my questions:
1. How do you validate Word and Excel files before upload?



Before?  JavaScript...if JavaScript can even do it (I haven't touched 
the stuff in ages).  After upload, you can check the mime type, but 
that's not foolproof.




Okay, sorry I miswrote: after upload to the temp directory, BEFORE using 
move_uploaded_file(). Checking the mime type is the problem - if I can't 
trust the browsers am I really reliant on the file extension? Can't I 
peek in some manner into it as we do with getimagesize()?


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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Mathieu Dumoulin

John Nichel wrote:

Jack Jackson wrote:
snip

Also, it seems that directories must be blown wide open (777) to allow 
the script to copy the file over from /tmp. My ISP won't allow 
directories to be set to 777 under public_html/ -- but we need to 
access the files via web browser which is the whole point.



It shouldn't have to be this way.  The webserver should be configured to 
run as your virtual user, or belong to a group which has write 
permission to that directory, or.I'm getting a bit off track with 
that.  This is something you'll have to take up with your ISP.



So my questions:
1. How do you validate Word and Excel files before upload?



Before?  JavaScript...if JavaScript can even do it (I haven't touched 
the stuff in ages).  After upload, you can check the mime type, but 
that's not foolproof.


2. How can I make a passthrough from a file above public_html to one 
below it so that people can surf in with a browser and download files 
which have been uploaded by the script?



http://us4.php.net/move_uploaded_file



Indeed file types are not fool proof, for example windows provide 
mime-type based on the file type in your system. Whatever browser the 
user has, if you don't have for example acrobat reader installed, all 
PDF files will be uploaded as application/octet-stream files.


So in no way should you ever validate a file based on its extension or 
on its mime type since 93% of the machines out there use extension to 
determine the mime type.


The only virtually failproof way to test for a certain file is using the 
header of the file. For example, getimagesize uses the header of the 
file to find what type of file it is. I wouln't recommend parsing the 
file, imagine someone uploaded a imposing 10 or even 100 mb file. The 
only way would be to read the first few characters and compare them with 
standard headers in those particular files. This will be an almost 
failproof way to see if an uploaded file is of the correct type.


The only 2 drawbacks to this method is:

- 1) Someone with malicious intentions CAN change the header of a file 
to force it to look like another type of file. What is the end result i 
dare not think about it. It could be used for any kind of hacking or 
damaging effect.


- 2) With ever changing versions of WORD and EXCEL, you need to 
implement a series of different headers for PC, MAC and even possibly 
LINUX if there is a version of these with slightly different headers. So 
i makes your code get heavier each year or so.


Mathieu Dumoulin

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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread John Nichel

Jack Jackson wrote:
snip

So my questions:
1. How do you validate Word and Excel files before upload?




Before?  JavaScript...if JavaScript can even do it (I haven't touched 
the stuff in ages).  After upload, you can check the mime type, but 
that's not foolproof.




Okay, sorry I miswrote: after upload to the temp directory, BEFORE using 
move_uploaded_file(). Checking the mime type is the problem - if I can't 
trust the browsers am I really reliant on the file extension? Can't I 
peek in some manner into it as we do with getimagesize()?


If your version of php has been configured with it, you can use 
mime_content_type()


http://us3.php.net/manual/en/function.mime-content-type.php

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



[PHP] Re: Strange notation to create object

2005-06-23 Thread Matthew Weier O'Phinney
* Michael Stepanov [EMAIL PROTECTED]:
 Usually, I develop on Perl. But my current task pushes me to start use
 PHP. Generally, it's great but sometimes I'm a little bit confused.
 For example, recently I've found a strange notation of creation of PHP
 objects:

 $obj =  new SomeObject();

 Can anyone explain me meaning of **?

 is used to create references -- kind of like \ in perl. 

The above notation is unnecessary when developing in PHP5, as objects in
PHP5 are passed by reference by default. However, in PHP4, this was
often necessary if you needed to, for instance, store an object in an
array or another object (otherwise you got a copy of the object, which
means state would then differ between the original and the copy).

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread symbulos
It looks like with curl you have to pass the parameters as external
variables appended to the link.

Is that the only way? Is it possible to simulate a POST behavior?

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



Re: [PHP] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread Jochem Maas

symbulos wrote:

It looks like with curl you have to pass the parameters as external
variables appended to the link.

Is that the only way? Is it possible to simulate a POST behavior?


yes. look here for an idea on how:

http://curl.haxx.se/mail/curlphp-2004-09/0063.html

bare in mind that POST is no more secure than GET - although obviously
POST params don't (generally!) get copy/pasted around by people [mistakenly]
... although in your case I doubt anyone would accidently copy/paste a GET url
from cURL addressbar ... mostly because cURL doesn't have an address bar ;-)

assuming you have php/apache compiled with SSL support you could make an
HTTPS connection with the ASP server to do the auto-login rather than plain
HTTP.





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



Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Jack Jackson



Tom Rogers wrote:

Hi,

Friday, June 24, 2005, 12:42:33 AM, you wrote:
JJ Hi,
JJ I checked at
JJ http://www.php.net/manual/en/features.file-upload.php and 
JJ all the user notes, and also the PEAR solution for uploading files and I

JJ still have a couple of questions.

JJ I need to create a form to allow users to upload (and later to delete)
JJ MS word, excel and jpg files. Through your help I was able to validate
JJ image files using getimagesize() and have made a nice script to upload
JJ and rename images.

JJ I cannot see a way to validate or examine Word or Excel files for 
JJ validity (and assume that older word files would validate differently

JJ from newer ones).

JJ The PEAR http upload script mentioned twice in the user notes at that
JJ manual page does not *seem* to validate other than denying certain
JJ extensions like php, php3, etc. I could be wrong of course.

JJ Also, it seems that directories must be blown wide open (777) to allow
JJ the script to copy the file over from /tmp. My ISP won't allow 
JJ directories to be set to 777 under public_html/ -- but we need to access

JJ the files via web browser which is the whole point.


JJ So my questions:
JJ 1. How do you validate Word and Excel files before upload?

JJ 2. How can I make a passthrough from a file above public_html to one
JJ below it so that people can surf in with a browser and download files
JJ which have been uploaded by the script?

JJ Thanks in advance,
JJ JJ

The first 8 bytes of an ole2 file (exel and word are ole2 files I
think) should have the following hex sequence:

\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1

So do an fopen and read in the first 8 bytes and compare it to that
string should give some indication.

Cl. Thank you Tom and all those who replied. I always learn so much 
here!


JJ

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



Re: [PHP] Strange notation to create object

2005-06-23 Thread Michael Stepanov

Rory Browne wrote:


It's in the manual.

PHP4
$obj = new SomeObject() would create a SomeObject, and assign it by
value to $obj. $obj would be a copy of the one created. by the new
SomeObject.  makes it assign by reference.

PHP5
In PHP5 Objects are assigned by reference anyway so the  doesn't matter.

 


Now I understand. Many thanks!


On 6/23/05, Michael Stepanov [EMAIL PROTECTED] wrote:
 


Dear all,

Usually, I develop on Perl. But my current task pushes me to start use
PHP. Generally, it's great but sometimes I'm a little bit confused.
For example, recently I've found a strange notation of creation of PHP
objects:

$obj =  new SomeObject();

Can anyone explain me meaning of **?

Thanks in advanced

--
Best regards,
Michael Stepanov
Perl/Linux Developer
Francoudi  Stephanou Ltd
Tel: +357 25-867154
Email: [EMAIL PROTECTED]

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


   




--
Best regards, 
Michael Stepanov

Perl/Linux Developer
Francoudi  Stephanou Ltd
Tel: +357 25-867154
Email: [EMAIL PROTECTED]

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Robert Cummings
On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
 * Michael Stepanov [EMAIL PROTECTED]:
  Usually, I develop on Perl. But my current task pushes me to start use
  PHP. Generally, it's great but sometimes I'm a little bit confused.
  For example, recently I've found a strange notation of creation of PHP
  objects:
 
  $obj =  new SomeObject();
 
  Can anyone explain me meaning of **?
 
  is used to create references -- kind of like \ in perl. 
 
 The above notation is unnecessary when developing in PHP5, as objects in
 PHP5 are passed by reference by default. However, in PHP4, this was

Not entirely, there's still a subtle difference in PHP5 between
assigning an object with = versus assigning with = .

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] array_search() with preg_match?

2005-06-23 Thread René Fournier

I need to search an array for a string, with a twist. E.g.:

$array = array(0 = 'this sky is blue', 1 = 'pencils are orange', 2 = 
'I like green apples', 3 = 'strawberries are red');


$key = array_search('green', $array);

With the above code, nothing will be returned, but I would like it to 
return 2 for the key containing green. Any suggestions?


...René

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



[PHP] Re-inserting newlines

2005-06-23 Thread Philip Thompson

Hi all.

I have searched for a way to figure out this problem, but nothing is  
popping up. Here's the scenario:


I have a form which I will write to a database - so I escape the form  
content. I have a textarea/textarea in the form. Obviously,  
people can type whatever they want to in this textarea, including  
newlines. Ok, I know how to escape the content to put it in the  
database - but if there is an error on the page, I want to redirect  
back to the page and correct their stuff.


So they have in one of the textareas:

--- start here ---
This is a line in the text area.

This is a line a couple of lines down in the text area.
--- end here ---

If I print the stuff back out to screen, it reads:

--- start here ---
This is a line in the text area.\r\n\r\nThis is a line a couple of  
lines down in the text area.

--- end here ---

Anyone know how/what to replace the \r\n in the textarea to that it  
shows up correctly with the actual newlines, not the \r\n???


Thanks in advance,
~Philip

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



Re: [PHP] Re-inserting newlines

2005-06-23 Thread John Nichel

Philip Thompson wrote:
Anyone know how/what to replace the \r\n in the textarea to that it  
shows up correctly with the actual newlines, not the \r\n???


You shouldn't need \r\n.  \n should work just fine.

How are you 'inserting' the newlines?  Single quoted string?

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Matthew Weier O'Phinney
* Robert Cummings [EMAIL PROTECTED] :
 On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
  * Michael Stepanov [EMAIL PROTECTED] :
   Usually, I develop on Perl. But my current task pushes me to start use
   PHP. Generally, it's great but sometimes I'm a little bit confused.
   For example, recently I've found a strange notation of creation of PHP
   objects:
  
   $obj =  new SomeObject();
  
   Can anyone explain me meaning of **?
  
   is used to create references -- kind of like \ in perl. 
  
  The above notation is unnecessary when developing in PHP5, as objects in
  PHP5 are passed by reference by default. However, in PHP4, this was

 Not entirely, there's still a subtle difference in PHP5 between
 assigning an object with = versus assigning with = .

Would you mind explaining the difference? I've seen nothing in the docs,
to indicate that assigning objects with = in PHP5 is necessary, or even
desired. My experience with PHP5 hasn't shown this either. I'd be
interested to know to what you refer.

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



[PHP] Re: array_search() with preg_match?

2005-06-23 Thread Bob Winter

René,
This may not the most efficient method, but works:

$array = array('this sky is blue', 'pencils are orange', 'I like green 
apples','strawberries are red');
$search = 'green';
$result = array();

foreach($array as $key1=$value1) {
  if(substr_count($value1, $search)) {
 $result[] = $key1;
  }
}

// $result is an array containing all the keys for the values that contained 
the search phrase
print_r($result);

// or convert to string
print implode(' ', $result);

// or however else to need to handle the results

--Bob

René Fournier wrote:

I need to search an array for a string, with a twist. E.g.:

$array = array(0 = 'this sky is blue', 1 = 'pencils are orange', 2 = 
'I like green apples', 3 = 'strawberries are red');


$key = array_search('green', $array);

With the above code, nothing will be returned, but I would like it to 
return 2 for the key containing green. Any suggestions?


...René



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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Robert Cummings
On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
 * Robert Cummings [EMAIL PROTECTED] :
  On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
   The above notation is unnecessary when developing in PHP5, as objects in
   PHP5 are passed by reference by default. However, in PHP4, this was
 
  Not entirely, there's still a subtle difference in PHP5 between
  assigning an object with = versus assigning with = .
 
 Would you mind explaining the difference? I've seen nothing in the docs,
 to indicate that assigning objects with = in PHP5 is necessary, or even
 desired. My experience with PHP5 hasn't shown this either. I'd be
 interested to know to what you refer.

See for yourself when running the following script:

?php

class a
{
}

class b
{
}

$aObj = new a();
$bObj = new b();

$foo1 = $aObj;
$foo2 = $aObj;
$foo3 = $foo1;
$foo4 = $foo2;

echo --\n;
print_r( $foo1 );
print_r( $foo2 );
print_r( $foo3 );
print_r( $foo4 );

$foo1 = $bObj;
$foo2 = $bObj;

echo --\n;
print_r( $foo1 );
print_r( $foo2 );
print_r( $foo3 );
print_r( $foo4 );

$foo1 = $aObj;
?

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

2005-06-23 Thread Philip Thompson

On Jun 23, 2005, at 12:20 PM, John Nichel wrote:


Philip Thompson wrote:

Anyone know how/what to replace the \r\n in the textarea to that  
it  shows up correctly with the actual newlines, not the \r\n???




You shouldn't need \r\n.  \n should work just fine.

How are you 'inserting' the newlines?  Single quoted string?


That's the thing, I'm not inserting \r\n at all. When filling in the  
form, I hit Enter to go to the next line in the textarea. When I  
pull the original data I do:


$textarea = mysql_real_escape_string($_POST[textarea], $connection);

if ($error) {
// somehow replace the \r\n that mysql_real_escape string put in

// then strip all the other slashes remaining: \' becomes '
$textarea = stripslashes($textarea);

// return to page
}

That clarify it a bit?
~Philip

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



Re: [PHP] Re-inserting newlines

2005-06-23 Thread John Nichel

Philip Thompson wrote:
snip
That's the thing, I'm not inserting \r\n at all. When filling in the  
form, I hit Enter to go to the next line in the textarea. When I  pull 
the original data I do:


$textarea = mysql_real_escape_string($_POST[textarea], $connection);

if ($error) {
// somehow replace the \r\n that mysql_real_escape string put in

// then strip all the other slashes remaining: \' becomes '
$textarea = stripslashes($textarea);

// return to page
}


$textarea = preg_replace ( /rn/, \n, $textarea )

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Matthew Weier O'Phinney
* Robert Cummings [EMAIL PROTECTED] :
 On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
  * Robert Cummings [EMAIL PROTECTED] :
   On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
The above notation is unnecessary when developing in PHP5, as objects in
PHP5 are passed by reference by default. However, in PHP4, this was
  
   Not entirely, there's still a subtle difference in PHP5 between
   assigning an object with = versus assigning with = .
  
  Would you mind explaining the difference? I've seen nothing in the docs,
  to indicate that assigning objects with = in PHP5 is necessary, or even
  desired. My experience with PHP5 hasn't shown this either. I'd be
  interested to know to what you refer.

 See for yourself when running the following script:

 ?php

 class a
 {
 }

 class b
 {
 }

 $aObj = new a();
 $bObj = new b();

 $foo1 = $aObj;
 $foo2 = $aObj;
 $foo3 = $foo1;
 $foo4 = $foo2;

 echo --\n;
 print_r( $foo1 );
 print_r( $foo2 );
 print_r( $foo3 );
 print_r( $foo4 );

 $foo1 = $bObj;
 $foo2 = $bObj;

 echo --\n;
 print_r( $foo1 );
 print_r( $foo2 );
 print_r( $foo3 );
 print_r( $foo4 );

 $foo1 = $aObj;
 ?

This doesn't demonstrate what the OP was talking about, which is initial
assignment of an object using a reference operator. The results of this
make perfect sense to me -- the references are passed exactly as I would
expect. 

Let me rephrase my question to you: is there a reason to do the initial
object assignment using a reference operator using PHP5? I.e., is there
a good reason to do this:

$foo = new Foo();

instead of:

$foo = new Foo();

I haven't seen any reason to do the former case using PHP5.

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



Re: [PHP] Strange notation to create object

2005-06-23 Thread John Hinton

Michael Stepanov wrote:

With a return receipt attached

and I'm wondering if we all return the receipt each time someone forgets 
about this on various mailing lists, would the 6583 subscribers actually 
returned the receipt, would it break the habit?


All in fun... sorry Michael.. it just happened to be yours that finally 
convinced me to send this. I just get tired of the interruption of my 
delete process.


Best,
John Hinton

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



Re: [PHP] Strange notation to create object

2005-06-23 Thread John Nichel

John Hinton wrote:

Michael Stepanov wrote:

With a return receipt attached

and I'm wondering if we all return the receipt each time someone forgets 
about this on various mailing lists, would the 6583 subscribers actually 
returned the receipt, would it break the habit?


All in fun... sorry Michael.. it just happened to be yours that finally 
convinced me to send this. I just get tired of the interruption of my 
delete process.


I don't even say anything about it anymore...just /dev/null when I see 
that return receipt box pop-up.


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Jason Barnett

Matthew Weier O'Phinney wrote:
...


This doesn't demonstrate what the OP was talking about, which is initial
assignment of an object using a reference operator. The results of this
make perfect sense to me -- the references are passed exactly as I would
expect. 



But not exactly as I would expect!  I thought that all objects were 
created as references, but apparently this is not the case.  Is there 
some kind of dereferencing going on when you're using an object on the 
right side of the assignment (=) operator?


In any case, assignment without  is a tricky thing to look out for and 
certainly can produce some really hard to detect bugs.  If the people 
that have been using PHP for years don't fully understand this... 
*whistling and walking away*



Let me rephrase my question to you: is there a reason to do the initial
object assignment using a reference operator using PHP5? I.e., is there
a good reason to do this:

$foo = new Foo();

instead of:

$foo = new Foo();

I haven't seen any reason to do the former case using PHP5.



Neither have I...

Slightly on-topic: I was browsing through PECL today and found an 
interesting looking extension called parsekit.  It will take your PHP 
code and show what the underlying opcodes are.  If I find some time 
tonight I'm going to play around with this extension and see if I can 
figure out how references are being handled by the engine.


P.S. Windows users: save your sanity and just get the .dll version 
instead of trying to build from source.  :)


http://snaps.php.net/win32/PECL_5_0/

--
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php

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



[PHP] Re: Showing tables (converting from MySQL to Oracle)

2005-06-23 Thread Catalin Trifu
Hi,

the USER_TABLES view shows all tables in oracle. Take a look at adodb.sf.net
for a very nice php library for database access. It takes much of the porting
burden off your shoulders and is pretty fast.

Catalin


Shane Presley wrote:
 Hello,
 
 I've recompiled PHP to use Oracle, and been able to run a quick test
 script that looks like...
 
 ?php
 if ($c=OCILogon(user, pw, server)) {
   echo Successfully connected to Oracle.\n;
   OCILogoff($c);
 } else {
   $err = OCIError();
   echo Oracle Connect Error  . $err[text];
 }
 ?
 
 
 So now I'm going through and converting my MySQL code to Oracle.  I've
 finished the connect functions, but getting hung up on how to do
 queries.  For example the first query wants to SHOW TABLES.  Not sure
 how to do this with Oracle calls?
 
 function get_tables($link) {
 $tableList = array();
 $query = SHOW TABLES;
 $result = perform_query($query, $link);
 while($row = fetch_array($result)) {
 array_push($tableList, $row[0]);
 }
 
 return $tableList;
 }
 
 
 function perform_query($query, $link) {
 if($link) {
 $result = mysql_query($query, $link) or die('Query
 failed: ' . mysql_error());
 }
 else {
 die('No DB link');
 }
 
 return $result;
 }
 
 
 Thanks!
 Shane

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



[PHP] Re: Sorting with french characters

2005-06-23 Thread Catalin Trifu
 Check the manual for sort www.php.net/sort - SORT_LOCALE_STRING
 You would have to pay attention to the current locale - 
www.php.net/setlocale
before the actual sort.

hope this solves it,
Catalin


Mathieu Dumoulin wrote:
 I've got a little problem with the ksort and sort functions. When i fill
  this array's keys or the array's data and i sort it, i can't seem to
 get a correct sort order concerning accented french characters.
 
 For example:
 
 Emiss, Erick
 Morrison, Phillip
 Tatey, Peter
 Zachary, Martin
 Élement, Marc-André
 
 This is the kind of result i get from Ksort when i put these as keys.
 Notice the Élement, Marc-André at the end? Its supossed to be in the
 Es not at the end.
 
 So i'm wondering how i can make this work now. I can't afford to make a
 STR_REPLACE on all possible accents, i got over a thousand records from
 the database to parse in a fast way and there are at the very least 60
 different accents to replace from the A, E, I, O and U without
 forgetting we have acute, grave, trema, circonflex accents for each
 letter. :S
 
 My guess is there is something in the configuration of my dev server
 that must do this. Can anyone help me?

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



[PHP] Re: Re-inserting newlines

2005-06-23 Thread JB05UK
This is the correct way to make a safe mysql query, see if it makes a 
difference, taken from:- 
http://php.net/manual/en/function.mysql-real-escape-string.php




?php
// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
   $value = stripslashes($value);
   }
   // Quote if not integer
   if (!is_numeric($value)) {
   $value = ' . mysql_real_escape_string($value) . ';
   }
   return $value;
}



// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
   OR die(mysql_error());

// Make a safe query
$query = sprintf(SELECT * FROM users WHERE user=%s AND password=%s,
   quote_smart($_POST['username']),
   quote_smart($_POST['password']));

mysql_query($query);

?









Philip Thompson wrote:

Hi all.

I have searched for a way to figure out this problem, but nothing is  
popping up. Here's the scenario:


I have a form which I will write to a database - so I escape the form  
content. I have a textarea/textarea in the form. Obviously,  people 
can type whatever they want to in this textarea, including  newlines. 
Ok, I know how to escape the content to put it in the  database - but if 
there is an error on the page, I want to redirect  back to the page and 
correct their stuff.


So they have in one of the textareas:

--- start here ---
This is a line in the text area.

This is a line a couple of lines down in the text area.
--- end here ---

If I print the stuff back out to screen, it reads:

--- start here ---
This is a line in the text area.\r\n\r\nThis is a line a couple of  
lines down in the text area.

--- end here ---

Anyone know how/what to replace the \r\n in the textarea to that it  
shows up correctly with the actual newlines, not the \r\n???


Thanks in advance,
~Philip


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



Re: [PHP] Re-inserting newlines

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 11:09 am, Philip Thompson said:
 On Jun 23, 2005, at 12:20 PM, John Nichel wrote:

 Philip Thompson wrote:

 Anyone know how/what to replace the \r\n in the textarea to that
 it  shows up correctly with the actual newlines, not the \r\n???

http://php.net/stripslashes

Your mysql_escape_string basically added slashes.

Actually, you *MIGHT* have Magic Quotes on in which case your real
problem is that *TWO* different mechanisms are adding slashes.

Magic Quotes calls http://php.net/addslasehes on everything in $_POST (and
$_GET)

Then, you call mysql_escape_string, and add a *SECOND* set of slashes.

Don't do that, first of all.

If Magic Quotes is on call stripslashes before you call
mysql_escape_string, or you'll just corrupt your data before you insert
it.

Also, the data you are inserting to the database, complete with escaped
characters, should not really be the data you are re-presenting to the
user if they need to change it.

You should be showing them un-escaped data.

Now, the data that comes back *OUT* of MySQL when you SELECT data that you
previously INSERTed is un-escaped -- The whole *point* of the escape
characters is to add characters that the MySQL parser eats up when it
reads in your data, thus correctly interpreting characters that would
otherwise be special

But the data you just tried to insert into MySQL, and didn't, for whatever
reason, is escaped data, and not suitable for presenting to the User.

If there is a mysql_unescape, use that.  If not, in an ideal world,
present them with the exact same data they gave you -- Only if you have
Magic Quotes on then you've already got http://php.net/addslashes called
on it, before you ever really saw it, so you still need to do
http://php.net/stripslashes to it.

 You shouldn't need \r\n.  \n should work just fine.

Yes, but...

The \r\n came about because his user is on Windows with a Windows browser
with Windows newlines.

While the browser and TEXTAREA are smart enough to handle \r\n or \n or
even just \r the same there's no need to jump through hoops to strip out
the \r for what you send back to the User if the data was bad

You *DO* want to convert \r\n and \r to \n for consistency in your
database, probably... Or maybe not...  I prefer to do that, but that's
just me, maybe.

 How are you 'inserting' the newlines?  Single quoted string?

 That's the thing, I'm not inserting \r\n at all. When filling in the
 form, I hit Enter to go to the next line in the textarea. When I
 pull the original data I do:

If you try it from a Linux browser, you're only gonna have \n

If you try it from a Mac browser, you're only gonna have \r

Windows is sending you \r\n, so that's what you got.  Deal with it, and be
prepared to deal with just \r and just \n.

 $textarea = mysql_real_escape_string($_POST[textarea], $connection);

 if ($error) {
  // somehow replace the \r\n that mysql_real_escape string put in

  // then strip all the other slashes remaining: \' becomes '
  $textarea = stripslashes($textarea);

  // return to page
 }

 That clarify it a bit?

If that is what you are doing, and it works, then your REAL problem is,
indeed, that Magic Quotes is on *AND* you are doing mysql_escape_string,
so you are double-addslashing (in effect).  Do *NOT* do that.  You'll make
a mess of your data real fast.

Then you'll end up using http://php.net/stripslashes on data coming *out*
of MySQL, because it has bogus extra \ in it, because you
double-addslashes before you did the INSERT.

This is a very common newbie error, and I can guarantee there are millions
of working scripts out there on the 'net that do exactly that:
Magic Quotes on does addslashes
Naive programmer does addslashes in PHP
Naive programmer sees bad data coming out of MySQL and does stripslashes

Two wrongs don't make a right.

You'll end up having data problems any time you want to use that data
anywhere else other than that broken application.

Use the example posted earlier to call stripslashes if Magic Quotes is on.

Store *THAT* string as what to send back to the User.

Use mysql_escape_string on that previous result.  Use *that* for your INSERT.

If there is a mysql_unescape_string, you could do that instead of storing
the result of your possible stripslashes...

Kinda ugly, though, particularly if your mysql_escape_string chops of 99%
of War and Peace because there is a semi-colon (;) in the first paragraph,
and it looks like a hack attempt.  The User will not be real happy that
your mysql_escape/unescape threw away 99% of what they typed...

I'm NOT claiming this is what mysql_escape_string *DOES* -- Only that it's
something reasonable like that which it *could* do at some point, if the
string looks funky enough to look like an attack on MySQL security.

-- 
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] Re-inserting newlines

2005-06-23 Thread Philip Thompson

On Jun 23, 2005, at 4:13 PM, Richard Lynch wrote:


On Thu, June 23, 2005 11:09 am, Philip Thompson said:


On Jun 23, 2005, at 12:20 PM, John Nichel wrote:



Philip Thompson wrote:



Anyone know how/what to replace the \r\n in the textarea to that
it  shows up correctly with the actual newlines, not the \r\n???



http://php.net/stripslashes

Your mysql_escape_string basically added slashes.

Actually, you *MIGHT* have Magic Quotes on in which case your real
problem is that *TWO* different mechanisms are adding slashes.

Magic Quotes calls http://php.net/addslasehes on everything in  
$_POST (and

$_GET)

Then, you call mysql_escape_string, and add a *SECOND* set of slashes.

Don't do that, first of all.

If Magic Quotes is on call stripslashes before you call
mysql_escape_string, or you'll just corrupt your data before you  
insert

it.

Also, the data you are inserting to the database, complete with  
escaped

characters, should not really be the data you are re-presenting to the
user if they need to change it.

You should be showing them un-escaped data.

Now, the data that comes back *OUT* of MySQL when you SELECT data  
that you

previously INSERTed is un-escaped -- The whole *point* of the escape
characters is to add characters that the MySQL parser eats up  
when it

reads in your data, thus correctly interpreting characters that would
otherwise be special

But the data you just tried to insert into MySQL, and didn't, for  
whatever
reason, is escaped data, and not suitable for presenting to the  
User.


If there is a mysql_unescape, use that.  If not, in an ideal world,
present them with the exact same data they gave you -- Only if you  
have
Magic Quotes on then you've already got http://php.net/addslashes  
called

on it, before you ever really saw it, so you still need to do
http://php.net/stripslashes to it.



You shouldn't need \r\n.  \n should work just fine.



Yes, but...

The \r\n came about because his user is on Windows with a Windows  
browser

with Windows newlines.

While the browser and TEXTAREA are smart enough to handle \r\n or  
\n or
even just \r the same there's no need to jump through hoops to  
strip out

the \r for what you send back to the User if the data was bad

You *DO* want to convert \r\n and \r to \n for consistency in your
database, probably... Or maybe not...  I prefer to do that, but that's
just me, maybe.



How are you 'inserting' the newlines?  Single quoted string?



That's the thing, I'm not inserting \r\n at all. When filling in the
form, I hit Enter to go to the next line in the textarea. When I
pull the original data I do:



If you try it from a Linux browser, you're only gonna have \n

If you try it from a Mac browser, you're only gonna have \r

Windows is sending you \r\n, so that's what you got.  Deal with it,  
and be

prepared to deal with just \r and just \n.


$textarea = mysql_real_escape_string($_POST[textarea],  
$connection);


if ($error) {
 // somehow replace the \r\n that mysql_real_escape string put in

 // then strip all the other slashes remaining: \' becomes '
 $textarea = stripslashes($textarea);

 // return to page
}

That clarify it a bit?



If that is what you are doing, and it works, then your REAL problem  
is,
indeed, that Magic Quotes is on *AND* you are doing  
mysql_escape_string,
so you are double-addslashing (in effect).  Do *NOT* do that.   
You'll make

a mess of your data real fast.

Then you'll end up using http://php.net/stripslashes on data coming  
*out*

of MySQL, because it has bogus extra \ in it, because you
double-addslashes before you did the INSERT.

This is a very common newbie error, and I can guarantee there are  
millions

of working scripts out there on the 'net that do exactly that:
Magic Quotes on does addslashes
Naive programmer does addslashes in PHP
Naive programmer sees bad data coming out of MySQL and does  
stripslashes


Two wrongs don't make a right.

You'll end up having data problems any time you want to use that data
anywhere else other than that broken application.

Use the example posted earlier to call stripslashes if Magic Quotes  
is on.


Store *THAT* string as what to send back to the User.

Use mysql_escape_string on that previous result.  Use *that* for  
your INSERT.


If there is a mysql_unescape_string, you could do that instead of  
storing

the result of your possible stripslashes...

Kinda ugly, though, particularly if your mysql_escape_string chops  
of 99%
of War and Peace because there is a semi-colon (;) in the first  
paragraph,
and it looks like a hack attempt.  The User will not be real happy  
that

your mysql_escape/unescape threw away 99% of what they typed...

I'm NOT claiming this is what mysql_escape_string *DOES* -- Only  
that it's
something reasonable like that which it *could* do at some point,  
if the

string looks funky enough to look like an attack on MySQL security.

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



Well, that was a 

Re: [PHP] Uploading and verifying word and excel files

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 7:42 am, Jack Jackson said:
 I cannot see a way to validate or examine Word or Excel files for
 validity (and assume that older word files would validate differently
 from newer ones).

If your PHP does not have the mime_type functions, you could probably use
http://php.net/exec with the file utility which does much the same thing
under Un*x-like systems.

man file on the command line for more info.

 The PEAR http upload script mentioned twice in the user notes at that
 manual page does not *seem* to validate other than denying certain
 extensions like php, php3, etc. I could be wrong of course.

Does it catch .asp, .cgi, .pl, .htm, .html, .jpg, .png, .gif, .jpeg, .pdf,
and .swf?

Cuz at certain directories on *my* server, those are all PHP scripts!

Well, okay, .pl and .cgi aren't.  Actually, I think I still have a .cgi
somewhere that *is* a PHP script...  It's equally dangerous either way.

Maybe someday they will be on your server, too, once you run into the
zillion IE bugs where the URL counts for more than the Content-type:
header.

It's really Bad Practice to rely on the last N characters of a filename as
some kind of Security Measure to stop a serious attack...

 Also, it seems that directories must be blown wide open (777) to allow
 the script to copy the file over from /tmp. My ISP won't allow
 directories to be set to 777 under public_html/ -- but we need to access
 the files via web browser which is the whole point.

Well, requring 777 just plain sucks...

You *should* have a directory writable by the PHP user/group as the
minimum requirement.

If PEAR really and truly requires 777, then that feature of PEAR sucks,
and you shouldn't use it.  Sorry, PEAR guys.  Gotta call 'em as I see 'em.

And if the best it can do is outlaw .php .php3 ..., then that ain't much
either.  I'd rather code it myself than have that weak of a safety.

 So my questions:
 1. How do you validate Word and Excel files before upload?

You don't.

Any validation done before upload is done on the client, and is therefore
something that can be easily bypassed by the savvy user.

It might be useful as a User-Interface feature to catch obvious stupid
mistakes by honest folk...

But it's USELESS as a Security Measure to stop Bad Guys.

Oh yeah:

You may need to use move_uploaded_file to move the files to a staging area
before you use exec/file on them...

At least, under *MY* webhost's setup, I can't directly read PHP uploaded
files from /tmp, even though PHP can move_uploaded_file() them... That may
have been changed/fixed, but it's a possible configuration issue.

So, use move_uploaded_file to let PHP do its checks, but put stuff in a
staging area that the PHP user can read/write, and is *NOT* in the
web-tree.

Then, do all of YOUR checks.  getimagesize, exec(/usr/bin/file $file...)
etc.

If that all passes, move the file (again) to its final destination, which
should *still* be out-side the web tree on most shared servers.

Write a PHP script that only allows files already listed in your database
to be served up, and which readfile's the data from outside the webtree to
spew it out.

*IF* you are on a dedicated server, or *IF* your webhost has a unique
UID/GID for you to have directories that no *OTHER* user on that webhost
can write to your PHP-writable directories/files, *then* it is
probably/maybe just as safe to put stuff in your webtree as to readfile it
from outside the web tree...

Even then, I'd only do the direct to webtree if performance was a major
issue.  It just doesn't make sense to me to let untrusted users put stuff
in the webtree where they might manage to trick the server into executing
it as Perl, PHP, JSP, ASP, or [deity] knows what code to do Evil things.

It's gonna be a lot tougher for them to fool PHP's readfile into executing
code.  Hell, if they can do that, they already own your server.

 2. How can I make a passthrough from a file above public_html to one
 below it so that people can surf in with a browser and download files
 which have been uploaded by the script?

There's an easy one. :-)

Put the files *OUTSIDE* your webtree.

Then write a PHP script that takes an ID of a valid uploaded file that
your previously stored in your database, looks up the path to that file,
and use http://php.net/readfile on it.

You were real close with passthrough which is http://php.net/passthru
which is kind of the same, only not.

You'd only put files in the webtree if PHP readfile proved too slow, *AND*
you were sure no user on the box could ever manage to infiltrate a
damaging file into the webtree...

That second one is a pretty Tall Order...

I can see somebody justifying it, but, honestly, if the overhead of
readfile is that big of a deal, then maybe you're living too close to the
edge on performance in the first place, and it's time to buy more/better
hardware anyway.

So, in MY opinion, you should NEVER put uploaded files from untrusted
users in the webtree.

Sure, if it's the site's 

Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Robert Cummings
On Thu, 2005-06-23 at 15:28, Matthew Weier O'Phinney wrote:
 * Robert Cummings [EMAIL PROTECTED] :
  On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
   * Robert Cummings [EMAIL PROTECTED] :
On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
 The above notation is unnecessary when developing in PHP5, as objects 
 in
 PHP5 are passed by reference by default. However, in PHP4, this was
   
Not entirely, there's still a subtle difference in PHP5 between
assigning an object with = versus assigning with = .
   
   Would you mind explaining the difference? I've seen nothing in the docs,
   to indicate that assigning objects with = in PHP5 is necessary, or even
   desired. My experience with PHP5 hasn't shown this either. I'd be
   interested to know to what you refer.
 
  See for yourself when running the following script:
 
  ?php
 
  class a
  {
  }
 
  class b
  {
  }
 
  $aObj = new a();
  $bObj = new b();
 
  $foo1 = $aObj;
  $foo2 = $aObj;
  $foo3 = $foo1;
  $foo4 = $foo2;
 
  echo --\n;
  print_r( $foo1 );
  print_r( $foo2 );
  print_r( $foo3 );
  print_r( $foo4 );
 
  $foo1 = $bObj;
  $foo2 = $bObj;
 
  echo --\n;
  print_r( $foo1 );
  print_r( $foo2 );
  print_r( $foo3 );
  print_r( $foo4 );
 
  $foo1 = $aObj;
  ?
 
 This doesn't demonstrate what the OP was talking about, which is initial
 assignment of an object using a reference operator. The results of this
 make perfect sense to me -- the references are passed exactly as I would
 expect. 
 
 Let me rephrase my question to you: is there a reason to do the initial
 object assignment using a reference operator using PHP5? I.e., is there
 a good reason to do this:
 
 $foo = new Foo();
 
 instead of:
 
 $foo = new Foo();
 
 I haven't seen any reason to do the former case using PHP5.

Your original response said that the above notation was unneccessary, I
took that to mean the  operator for reference. Looking back I see ow
that your comment was ambiguous, and I agree there is no need for the 
when assigning a new object. I was merely clarifying that references and
normal assignment are not synonymous for objects in PHP 5.

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] Sorting with french characters

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 7:37 am, Mathieu Dumoulin said:
 STR_REPLACE on all possible accents, i got over a thousand records from
 the database to parse in a fast way and there are at the very least 60

Odds are REALLY GOOD you can get the database to ORDER BY using your
locale/language/charset of choice, and get it MUCH MUCH MUCH faster than
ksort.

You're should ask How on a mailing list for your database, though.

-- 
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] Accessing forms through php

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 3:24 am, José Miguel López-Coronado said:
 I have seen how to use cURL to retreive results from a web site after
 processing a form. The problem is that I want to simulate completely the
 submiting of a form, I mean, I wan to enter the page in the server
 instead of retreive the results into my own page. I'm trying to use a
 php script to login into a site without having to enter user and pass.
 Anyone knows how to do this using cURL or any other option like HEADER
 or something like that?

You will need to do curl_execute() or whatever it is several times.

First, you'll user cURL to *read* the page with the FORM in it.  This may
(or may not trigger) some Cookies and/or some embedded tokens in the FORM
that you may need.

If it has no cookies and nothing fancy embedded in the FORM, then you may
be able to comment out this first chunk of code, after you figure out that
you don't need it, and you can proceed to Step 2.

Do *NOT* delete this code.  You may need it tomorrow if they change their
login routine.  Been there.  Done that.  Keep the code.

Second, you'll then need to send a POST with curl of the
username/password, and, again, get all the results.

This step will almost certainly send a Cookie, or embed some kind of token
in the URLs and FORMs that you need to catch and pass on to all subsequent
HTTP/HTTPS requests.

Third, you can request whatever it is you wanted in the first place, but
you need to pass in the Cookies and tokens you got from the second step.

Many of these pages might, or might not, return 302 headers for Object
Moved  If it's an MS/ASP/.net site, it will have a bunch of them, mostly
bogus, because you can bypass them, usually.

Again, you want to keep the code around in case some day they change their
login procedure and those stupid re-directs actually have meaning.

Right now, they just waste resources and sell more hardware for Microsoft,
but is that really a shock?

Reverse-engineering the login of a page can be challenging.  Sometimes
stuff you think is totally un-necessary turns out to be needed.

Here are some hard-won Tips:

1. The button clicked on for login (or other form submission) may or may
not have a NAME=... parameter.

If it has a NAME=... parameter, you *may* need to pass in its
VALUE=... as one of your arguments in the POST/GET with curl to make it
work.

While it's less likely you need it, I've seen at least one site where they
RELY on the default NAME=... being Submit and its value of Submit
and, yes, you had to pass those in to get past the gate. [shudder]

2. You need to catch/send Cookies.  I never did get that automated Cookie
Jar feature of curl to work for me.  But it helps to see the Cookie
variable names and values to figure out what the other programmer did (or
didn't do) for their login process anyway, so you might as well manage
them by hand.

3. In some cases, I needed to use a whole new curl handle to send the next
request.  Later research indicated that maybe curl was doing a POST by
default after it had done POST the last time, and I should have
over-ridden that...  It was easier to just keep the code that get a fresh
curl handle. In a high-performance situation, you might maybe care to fix
that better.  I didn't.

4. Keep debug output that dumps out the HTML you get at each step. 
Comment it out, but keep it. Document in the code itself what you found
were the relevant elements that you needed to achieve the next HTTP
interaction.  Also comment anything funky that you thought would be
relevant/needed data, but turned out to be useless, or even detrimental to
send back on the next request.  Yesterday's junk could be tomorrow's gold.

5. Dump out all headers and all HTML in your first debug code. When you
think you know what's relevant, add more debug code below that to dump out
the relevant stuff, and comment out the verbose debug code that dumps
everything out.  When you're *SURE* you have it right, and can login not
just today, but also tomorrow, and also from another computer or three,
then comment out the concise debug code.  Keep all of it.  You'll need it
again when they change their login.

6. Set up your own PHP script on your own server that spits out all the
headers sent by an HTTP request, and then be ready to copy/paste their
output in as your output.  Sometimes the silliest things are used by them
to try to stop your robot from logging in.  User Agent springs to mind. 
Anything your browser sends as a header is fair game for them to be
checking, even if they are violating HTTP standards.  Hey, this is the
real world. You *WILL* find a site that violates standards really fast if
you dig into this very much.

7. It's kind of fun in a hacker-sort of way to work through the login
process of another site and see how it all fits together.  It's certainly
instructive!  It can also be challenging.  If you're stuck, take a break. 
Staring at the code and their HTTP output is unlikely to be fruitful after
any length of 

Re: Re[2]: [PHP] comparing two texts

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 5:25 am, Tom Rogers said:
 Hi,

 Thursday, June 23, 2005, 9:42:34 PM, you wrote:
 .
 .
 .

 JM whereas I'll happily spend an hour writing up and contemplating
 someone
 JM else's problem - I don't have five minutes for people who are
 expecting to be
 JM spoonfed (go learn ASP and get a support contract, thanks ;-).

 Perhaps I missed it but could you point out the bit where the original
 poster asked to be spoon fed??

After she rejected using exec(diff) and then rejected a starter script
to roll her own and then said I guess it can't be done ???

Sounds like a request to have the pre-built PHP function already written
to do exactly what she wanted to me.

But maybe we're just being dense and not understanding what she wanted...

I doubt it, though.

I don't care, though.  Today's newbie is tomorrow's Programmer.  Some day
she'll maybe write that script she deemed impossible today, and contribute
it back to the community.

Or maybe she'll some day add a PHP Module to interface directly to diff
somehow.

Or maybe somebody else will read this thread and be inspired to write one
and contribute it.

Maybe it will spawn a hundred different 'diff' classes in the future.

Maybe it will die an ignomious death.

You makes your posts and you takes your chances.

[shrug]

If you get all bent out of shape by everybody that comes down the pike and
doesn't like that there isn't the phpBB equivalent of a diff feature
out there (or whatever feature they want) then you're in the wrong
place...

Lots of people build perfectly fine websites with pre-assembled large
bodies of code.  More power to them.

So they ask for Feature X and go away disappointed it's not there ready
for them.  Okay.

Enough of them ask, one of them will build it.

That's the beauty of OpenSource.

If you get discouraged by the 1,000 that ask before the one that builds...
 Re-think your commitment to OpenSource.

Enough philosophising.

Time to code.

-- 
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] Re: Help recognizing bots?

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 3:37 am, JamesBenson said:
 http://www.funender.com/phpBB2/about18577.html

Call me crazy, but...

A)
Doesn't robots.txt have to be in public_html?  How the hell can the robots
read it if it's in the root folder, as they suggest in that forum?

B)
Are the Bad Bots really going to honor robots.txt in the first place?  I
mean, I know the spammers don't even need to un-obfuscate emails as simple
as %40 and #64; but are they really so dumb as to honor robots.txt while
they write their crawlers?... That's crazy.

Though I guess my theory on that holds true here as well:  If you catch a
million fish every time you cast your line, are you gonna try better bait?
 No.  So they don't un-obfuscate even the simplest email mask, and I guess
some of them play nice as far as robots.txt goes, even though they are out
to spam you.  Seems silly, but that could be Reality.

C)
Aren't some of those bad bots also going to rule out legitimate
scripting?  Am I mistaken that he pre-emptorally denies access to any
(legit) Python script? Hello? I'm not a fan of Python, but that seems a
bit much. :-)
[Just kidding.  I'm ambivalent towards Python, really.]

-- 
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] passing login paramters from php web application to asp web application. help.

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 12:33 am, symbulos said:
 Richard Lynch wrote:
 You simply have to convince the other site that your PHP script actually
 *IS* the user logging in, which is seldom very tricky, and is always
 *POSSIBLE* with enough effort.

 How can be that done? Do you know of any tutorial, example?

Just the examples in http://php.net/curl and following pages.

It's a LOT easier than you think when you sit down to do it.

You send the same crap to their web-server that a browser sends.

They send back the same HTTP/HTML crap your browser gets.

You use PHP to find the bits and pieces relevant to getting to the next
URL, and you start over with sending the same crap your browser sends.

Repeat all that as necessary, and you reach your goal.

I posted a lot more detail already a few minutes ago, but wanted to stress
that despite the finicky details, it's just not that tricky.

I think EVERY web developer should do this, at least once, just to realize
just how *NOT* tricky it is to fool a login if a determined Bad Guy
wants to.

It will make you appreciate so much more what Security really is, and why
a simplistic login isn't really much of a barrier -- And you have a better
understanding of what goes on during a login process that *is* good.

If anybody teaches a PHP course of any length, this should be a required
assignment:

Using a known valid login for a site that requires username/password,
write a PHP script that gets through that login to protected content.

Let the students pick the site, and share their results.  They'll all
learn a whole lot more that way from each other's experience.

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



[PHP] fopen problem

2005-06-23 Thread Ross
I have a bit of a problem when using fopen, fwrite and fclose locally I get 
the flowing warnings

Warning: fopen(counterlog.txt) [function.fopen]: failed to open stream: 
Permission denied in c:\Inetpub\wwwroot\pillars\index.php on line 30

Warning: fwrite(): supplied argument is not a valid stream resource in 
c:\Inetpub\wwwroot\pillars\index.php on line 33

Warning: fclose(): supplied argument is not a valid stream resource in 
c:\Inetpub\wwwroot\pillars\index.php on line 36


Any ideas??


R. 

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



Re: [PHP] fopen problem

2005-06-23 Thread Esteamedpw
can you show the code? did you chmod the files?


Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Matthew Weier O'Phinney
* Robert Cummings [EMAIL PROTECTED] :
 On Thu, 2005-06-23 at 15:28, Matthew Weier O'Phinney wrote:
  * Robert Cummings [EMAIL PROTECTED] :
   On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
* Robert Cummings [EMAIL PROTECTED] :
 On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
  The above notation is unnecessary when developing in PHP5, as 
  objects in
  PHP5 are passed by reference by default. However, in PHP4, this was

 Not entirely, there's still a subtle difference in PHP5 between
 assigning an object with = versus assigning with = .

Would you mind explaining the difference? I've seen nothing in the docs,
to indicate that assigning objects with = in PHP5 is necessary, or even
desired. My experience with PHP5 hasn't shown this either. I'd be
interested to know to what you refer.
  
   See for yourself when running the following script:

snip -- code sample

  
  This doesn't demonstrate what the OP was talking about, which is initial
  assignment of an object using a reference operator. The results of this
  make perfect sense to me -- the references are passed exactly as I would
  expect. 
  
  Let me rephrase my question to you: is there a reason to do the initial
  object assignment using a reference operator using PHP5? I.e., is there
  a good reason to do this:
  
  $foo = new Foo();
  
  instead of:
  
  $foo = new Foo();
  
  I haven't seen any reason to do the former case using PHP5.

 Your original response said that the above notation was unneccessary, I
 took that to mean the  operator for reference. Looking back I see ow
 that your comment was ambiguous, and I agree there is no need for the 
 when assigning a new object. I was merely clarifying that references and
 normal assignment are not synonymous for objects in PHP 5.

Okay -- good to see that we're on the same page. I was worried I'd
missed something critical in the manual!

References aren't easy to wrap your head around; I, for one, am very
happy that I don't need to worry about them nearly as much with PHP5
(syntax is now, do what I mean).  Interestingly enough, however, the
PHP4 behaviour is actually much closer to perl's -- which should have
made it easier for me (being a perl programmer), but somehow didn't.

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Matthew Weier O'Phinney
* Jason Barnett [EMAIL PROTECTED] :
 Matthew Weier O'Phinney wrote:
 ...
  This doesn't demonstrate what the OP was talking about, which is initial
  assignment of an object using a reference operator. The results of this
  make perfect sense to me -- the references are passed exactly as I would
  expect. 

 But not exactly as I would expect!  I thought that all objects were 
 created as references, but apparently this is not the case.  

Here's what happens (in PHP5) with the statement '$obj = new Class();':

* the 'new Class()' construct creates an object
* it then returns a reference to the object
* assignment is then to the reference

Thus, $obj is actually a *pointer* to the object -- not the actual
object.

 Is there some kind of dereferencing going on when you're using an
 object on the right side of the assignment (=) operator?

No. It's simpler: you're simply passing around a reference to the
object. 

Before, in PHP4, when you would use assignment, the variable on the left
side would receive a *copy* of the object on the right -- a clone of the
object. *UNLESS* what you had on the right side was a reference; then it
would clone the reference, meaning you have the same behaviour as in
PHP5.

This is why the $obj = new Class() idiom occurred in PHP4; that way you
could pass around your object safely, because you were simply passing
around a reference to an object. PHP5 simplifies this by simply
assigning the object reference only in the first place.

-- 
Matthew Weier O'Phinney   | WEBSITES:
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED] | http://vermontbotanical.org

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



Re: [PHP] Re: Strange notation to create object

2005-06-23 Thread Robert Cummings
On Thu, 2005-06-23 at 21:44, Matthew Weier O'Phinney wrote:
 * Jason Barnett [EMAIL PROTECTED] :
  Matthew Weier O'Phinney wrote:
  ...
   This doesn't demonstrate what the OP was talking about, which is initial
   assignment of an object using a reference operator. The results of this
   make perfect sense to me -- the references are passed exactly as I would
   expect. 
 
  But not exactly as I would expect!  I thought that all objects were 
  created as references, but apparently this is not the case.

There's a difference between a reference to a reference and a copy of a
reference *hehehe*.

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: Strange notation to create object

2005-06-23 Thread Evert | Rooftop Solutions

Robert Cummings wrote:


On Thu, 2005-06-23 at 13:36, Matthew Weier O'Phinney wrote:
 


* Robert Cummings [EMAIL PROTECTED] :
   


On Thu, 2005-06-23 at 11:32, Matthew Weier O'Phinney wrote:
 


The above notation is unnecessary when developing in PHP5, as objects in
PHP5 are passed by reference by default. However, in PHP4, this was
   


Not entirely, there's still a subtle difference in PHP5 between
assigning an object with = versus assigning with = .
 


Would you mind explaining the difference? I've seen nothing in the docs,
to indicate that assigning objects with = in PHP5 is necessary, or even
desired. My experience with PHP5 hasn't shown this either. I'd be
interested to know to what you refer.
   



See for yourself when running the following script:

Cheers,
Rob.
 


I am stunned! Since I try to make my code working for both PHP4 and PHP5
I try to never rely on PHP4's standard cloning behaviour, and use 
where I can, so I have never really encountered this, but this will
propably save my a lot of frustration when the rest of the world says
goodbye to PHP4. (I remember when I first encountered the 'references in
constructor'-issue)

excellent stuff!

grt,
Evert

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



Re: [PHP] Socket server in PHP

2005-06-23 Thread Richard Lynch
On Wed, June 22, 2005 11:52 pm, kioto said:
 Hi all sorry for the ignorance :D.This is my first time with Socket and
 i have
 a question for you.I want create a script that run like daemon in
 background
 and listen incoming request.It's possible with socket open a stream to a
 directory
 and check any change on this directory ?
 I want send notify about the state of directory through e-mail for
 example:
 when a user add  new files or change any data.

Sort of.

I don't think you need anything as fancy as a Socket to do what you want.

Just:

http://php.net/filemtime on the directory to detect contents changed
http://php.net/opendir and readdir to see what's in it
http://php.net/clearstatcache to make PHP forget cached status of the above
http://php.net/mail to send whatever emails you want

An infinite loop with http://php.net/sleep to do this every few seconds.

You'd maybe want to use http://php.net/pcntl to respond to system signals...

You'd maybe want to store the current filemtime and current directory
contents in a database or file so you'd be able to start/stop your process
and still send every email for all changes, even the ones that happen
while your program wasn't running.

You could maybe launch it from the shell with nohup to NOT get killed,
as I sort of understand it... Better read man nohup I think...

Assuming it's RedHat or similar, you'd want to write a /etc/rc.d/init.d
shell script to start/stop the PHP script.

I dunno where you thought you'd want a Socket in all this. [shrug]  Maybe
I'm missing something...

Or did you want to have it respond to requests for info about a specific
directory?

Perhaps what you REALLY want is another process that listens on a Socket
to register the email has an interest in a specific directory.  But you
could do that in a web FORM just as easily.  Then your program above would
run through all the email/directory combinations and do its thing in a
more granular manner.

-- 
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] Help with image map problem...

2005-06-23 Thread Richard Lynch
On Wed, June 22, 2005 10:16 pm, Joey said:
 If I put this in the .php file, the results are as expected:
 Value: % echo $value; %

 If in the SAME file I put:
 map name=FPMap0
 area href=display_status.php?searchby=cust_nosearch=1value=% echo
 $value % shape=rect coords=51, 1, 215, 34
 /map

I'm gonna go out on a limb and put my money on:

Your map stuff is inside of a FUNCTION block, where $value is not defined.

You need to pass $value into your function.

Or you could declare it global in the function, but that's just icky.



-- 
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] Extra (persistant) tier

2005-06-23 Thread Richard Lynch
On Wed, June 22, 2005 8:35 pm, Leila Lappin said:
 When I worked with other OO languages, I usually designed my persistent
 business objects in two levels.  A level (lower level) designed and
 implemented direct database calls.  Each database table had a class
 abstraction at this level which provided the database calls for saving,
 loading and etc.  At this level I also provided for the caching
 considerations, i.e. if a table was already queried and a list was
 available
 the list in memory was used instead of querying again.

I had a guy hired me to do that once.

He had me budgeted for about a month to write all the classes.

I spent two days writing a PHP script to write a PHP class for each table
in the database, using mysql_* introspection functions instead. :-)

He was pretty happy, since I saved him about $10,000, give or take.

The project died long before he ever got to the point of having me do the
next level...

Which is just as well.

I REALLY don't understand why anybody would abstract out every single
table as a separate class like that.

Surely there are some COMMON features and behaviours between the fields of
any given MySQL type.

Wouldn't it make a LOT more sense to have a single abstract class that,
given a MySQL table-name, would provide an object cache of data structures
that matched the table field names/types?

Surely the text field in table foo isn't all that different from the
text field in table bar at that level.

Maybe that's just me being ornery.

 The next level was where the business model was implemented.  If a
 business
 object required information from three tables that related to each other
 in
 a certain way the load methods would access the objects from cached lists
 in
 three different classes (each representing a database table) and created
 the
 final list.  At this stage the list was cached and also represented the
 business logic.

Woof.

Now see, there, I gotta wonder is your cache really faster than a good
single query?

Cuz I'm thinking three separate queries for the data is gonna be a lot
more expensive.  Sure, maybe it's cached.  Or maybe it's not.

With the relatively SHORT life-time of a PHP script (you hope) the odds on
any given datum being cached should be pretty LOW, I would think.

Plus, the way this works out, you're probably going to end up having a
separate query for every row if you are displaying, say, 10 rows of
inter-related data from three tables.

That's 30 queries instead of 1.

That can't be faster than one well-written query.

 Although I haven't done this in PHP I think with PHP5 it's possible.  The
 only challenge may be the caching of query results but I think Pear
 modules
 already have something about that.

Caching query results should be relatively easy...

Of course, your DATABASE server and your Operating System are *already*
caching data for you. Will your cache on top of their cache really provide
significant performance boost in PHP?

Plus, if you design the Application Logic correctly, you shouldn't *HAVE*
duplicate queries to get the same data in a single script.

This whole data-cache thing might make sense in a language where there is
a central shared cache (Java?  JSP?) but in PHP I just don't see it being
all that

By the time you've filled up your cache with all the stuff you are going
to re-use, the script should be FINISHING.

PHP is not Java.

The solutions that are great in Java aren't in PHP sometimes.  And vice
versa, of course.

Now if you combine this with some kind of PHP Application Framework, and
throw away the whole point of the cornerstone of the share-nothing
architecture (which has pros and cons) then you might maybe have a
significant performance increase...  But there ain't such a beast yet, far
as I know, though some folks are working on them.

So, I gotta say, if you did this in PHP, you've made a fundamental error
in assessing the performance/benefit/cost ratios of what makes a PHP
Application fast.

This is all just MY OPINION.

I'm sure somebody is going to tell me just how stupid and naive I mussed
be for not undersanding OO.

Never mind I spent 15 years hacking in Common Lisp where damn near
*everything* is an object and some of my OO code is still in production
use 10 years after it was written.

Somebody's bound to post how the maintainability would be SOOO much better
it's worth the performance price.  I disagree.

I believe there are BETTER abstraction models for how PHP works than the
one class per db table.

-- 
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] fopen problem

2005-06-23 Thread Richard Lynch
On Thu, June 23, 2005 4:33 pm, Ross said:
 Warning: fopen(counterlog.txt) [function.fopen]: failed to open stream:
 Permission denied in c:\Inetpub\wwwroot\pillars\index.php on line 30

The PHP user does *NOT* have permission to open the counterlog.txt file.

Exactly *HOW* you change permissions changed in every Windoze version,
which suck, but there it is.

You should A) post *which* Windows OS you are using and B) try the Windows
list and C) poke around with Windows Explorer first to see if you can't
make the counterlog.txt file be owned by the User PHP is running as, which
you can find out from http://php.net/phpinfo

Actually, do ABC) in reverse order :-)

 Warning: fwrite(): supplied argument is not a valid stream resource in
 c:\Inetpub\wwwroot\pillars\index.php on line 33

 Warning: fclose(): supplied argument is not a valid stream resource in
 c:\Inetpub\wwwroot\pillars\index.php on line 36

These are a direct result of the first error.

Your script should NOT have even *TRIED* to run these functions, once it
failed to open the file in the first place.

Add a lot more error-checking to your script.

Once you fix the first error, these errors will go away

In Reality, they are just waiting to re-surface when something else goes
wrong with your file access.

So, actually, fix your script to skip these lines *FIRST* then fix the
error above.  Consider it part of the learning to write Good Code.

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