[PHP] Sending the results of a query without using a file

2007-05-02 Thread Todd Cary
Some shared servers do not allow the creation of a file, so I am 
looking for a way to take the results of a query (MySQL), create 
a CSV output and have it in a sendable format for the user 
without creating a file.


Many thanks

Todd

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



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread Kevin Waterson
This one time, at band camp, Todd Cary [EMAIL PROTECTED] wrote:

 Some shared servers do not allow the creation of a file, so I am 
 looking for a way to take the results of a query (MySQL), create 
 a CSV output and have it in a sendable format for the user 
 without creating a file.

sendable to where?

kevin

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

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



[PHP] Split string

2007-05-02 Thread Lester Caine
Can someone with a few more working grey cells prompt me with the correct 
command to split a string.


The entered data is names, but I need to split the text up to the first space 
or comma into one string, and the rest of the string into a second. It's the 
'first either space or comma' that eludes me at the moment :(


In know it's probably obvious, but it always is when you know the answer.

--
Lester Caine - G8HFL
-
Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://home.lsces.co.uk
MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Firebird Foundation Inc. - http://www.firebirdsql.org/index.php

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



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread clive

Todd Cary wrote:
Some shared servers do not allow the creation of a file, so I am looking 
for a way to take the results of a query (MySQL), create a CSV output 
and have it in a sendable format for the user without creating a file.




are you sure, then how could you say ftp the files to the server, are 
you not trying to create files in the wrong directory?


hmm if you want to allow the user to download the file, then just send 
the correct headers, using the header() function, for the csv format and 
then echo the contents of the file.


remember your application may spit out some other bits of text and this 
will interfere with sending the headers so you may also need to look at 
the output control functions to clean the outout buffer and then send 
your headers and data:

http://www.php.net/manual/en/ref.outcontrol.php

Regards,

Clive.

{No electrons were harmed in the creation, transmission or reading of 
this email. However, many were excited and some may well have enjoyed 
the experience.}


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



Re: [PHP] Split string

2007-05-02 Thread Fredrik Thunberg

Lester Caine skrev:
Can someone with a few more working grey cells prompt me with the 
correct command to split a string.


The entered data is names, but I need to split the text up to the first 
space or comma into one string, and the rest of the string into a 
second. It's the 'first either space or comma' that eludes me at the 
moment :(


In know it's probably obvious, but it always is when you know the answer.



$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ? 
strpos($myString,  ) : strpos($myString, ,);


$part1 = substr($myString, 0, $pos);
$part2 = substr($myString, $pos);

/T

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



RE: [PHP] PHP Command line script

2007-05-02 Thread Peter Lauri
Check the error from mysqli:

http://fi.php.net/manual/en/function.mysqli-error.php

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

 -Original Message-
 From: Nathaniel Hall [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, May 01, 2007 10:13 PM
 To: php-general@lists.php.net
 Subject: [PHP] PHP Command line script
 
 I am attempting to run a script that will run from the command line
 nightly to update a field in a database.  I already created a script
 that would access the database and insert most of the information when a
 webpage is visited and I had no problems with it.  The command line
 script appears to fail on the prepare.  I have echo'ed the SQL statement
 to the screen, copied it, and run it on the MySQL server with no
 problems.  Any ideas?
 
 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
 any further than here, even when hard coding the information.
 $logout-bind_param(s, date('m\-d\-
 Y\TH\:i\:s'));
 $logout-execute();
 $logout-close();
 }
 }
 $mysqli-close();
 ?
 
 --
 Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
 Spider Security
 
 --
 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] Sending the results of a query without using a file

2007-05-02 Thread Tijnema !

On 5/2/07, clive [EMAIL PROTECTED] wrote:

Todd Cary wrote:
 Some shared servers do not allow the creation of a file, so I am looking
 for a way to take the results of a query (MySQL), create a CSV output
 and have it in a sendable format for the user without creating a file.


are you sure, then how could you say ftp the files to the server, are
you not trying to create files in the wrong directory?


I have that too on one of my shared hosts, I can't create any files in
my home directory, because the PHP user doesn't have access rights
there, chmodding all directories did fix, (done through SSH). Before i
figured out that I could chmod all directories, I found out that it
does allow me to write in /tmp, and so i stored my files there, but
only temporary of course, because /tmp is cleaned regularly


hmm if you want to allow the user to download the file, then just send
the correct headers, using the header() function, for the csv format and
then echo the contents of the file.


Yep, that's the correct way.


remember your application may spit out some other bits of text and this
will interfere with sending the headers so you may also need to look at
the output control functions to clean the outout buffer and then send
your headers and data:
http://www.php.net/manual/en/ref.outcontrol.php

Regards,

Clive.


I don't think that you will need output buffering, most functions
allow you (or only) return values.

Tijnema








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



Re: [PHP] Split string

2007-05-02 Thread Lester Caine

Fredrik Thunberg wrote:

Lester Caine skrev:
Can someone with a few more working grey cells prompt me with the 
correct command to split a string.


The entered data is names, but I need to split the text up to the 
first space or comma into one string, and the rest of the string into 
a second. It's the 'first either space or comma' that eludes me at the 
moment :(


In know it's probably obvious, but it always is when you know the answer.


$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ? 
strpos($myString,  ) : strpos($myString, ,);


$part1 = substr($myString, 0, $pos);
$part2 = substr($myString, $pos);


I'm glad I asked now, that is a lot nicer than trying to get the preg_split 
thing working :)


--
Lester Caine - G8HFL
-
Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://home.lsces.co.uk
MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Firebird Foundation Inc. - http://www.firebirdsql.org/index.php

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



Re: [PHP] Split string

2007-05-02 Thread Stut

Fredrik Thunberg wrote:

Lester Caine skrev:
Can someone with a few more working grey cells prompt me with the 
correct command to split a string.


The entered data is names, but I need to split the text up to the 
first space or comma into one string, and the rest of the string into 
a second. It's the 'first either space or comma' that eludes me at the 
moment :(


In know it's probably obvious, but it always is when you know the answer.



$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ? 
strpos($myString,  ) : strpos($myString, ,);


Suggest the following as being more efficient (half the strpos calls)...

$pos = min(strpos($myString,  ), strpos($myString, ,));

Alternatively you could use split to break the string into the two 
parts, which is probably more efficient...


list($part1, $part2) = split('[ ,]', $myString);

-Stut

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



Re: [PHP] Split string

2007-05-02 Thread Stut

Stut wrote:
Alternatively you could use split to break the string into the two 
parts, which is probably more efficient...


list($part1, $part2) = split('[ ,]', $myString);


Oops, this should have a third parameter...

list($part1, $part2) = split('[ ,]', $myString, 2);

-Stut

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



[PHP] Sockets as a module or a separate PHP CLI instance?

2007-05-02 Thread list3
I need to do some socket work on a production machine that is constantly
busy so I don't dare re-compile php. Anybody know if it's possible to load
the socket functions dynamically, maybe as if they were in a module?
Alternatively, would it be possible to compile PHP without apache and with
sockets for command line use only? If I do that I would like to give the
resulting object a different name than PHP because I do have some cmd line
pgms running on the machine. Is that difficult?

Tx,
Paul W

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



[PHP] Extract and verify SSL signature form x509 certificate.

2007-05-02 Thread D.EIiM - Lluís Pàmies i Juarez

I've a x509 certificate from my CA self-signed:
$res_ca_cert=openssl_csr_sign($res_ca_csr,NULL,$res_ca_key,365);

Then, I've an user certificate signed by the CA:
$res_usr_cert=openssl_csr_sign($txt_usr_csr,$txt_ca_cert,$res_ca_key,1);

Exists in the PHP API any function to check if the user certificate is 
really signed by the CA ? Like this operation :


  $res_ca_public = openssl_get_publickey($txt_ca_cert);
  $txt_usr_sign = fakessl_x509_getsignature($txt_usr_cert);
  openssl_public_decrypt($txt_usr_sign,$txt_usr_public,$res_ca_public);
  Check that $txt_usr_public == fakessl_gettxt_publickey($txt_usr_cert)

I've found openssl_pkcs7_verify, but this doesn't work for me because I 
can access to the file system.


Another solutions is to parse the human-readable x509 certificates in 
order to get the public keys and certificates and verify it by hand.


Any idea ?

Thanks for all !

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



[PHP] Re: Sockets as a module or a separate PHP CLI instance?

2007-05-02 Thread Man-wai Chang

[EMAIL PROTECTED] wrote:

I need to do some socket work on a production machine that is constantly
busy so I don't dare re-compile php. Anybody know if it's possible to load
the socket functions dynamically, maybe as if they were in a module?


I think both Fedora Core and Ubuntu do it. Check out their RPM/DEB spec 
file for compiling the packages.


--
  .~.   Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
 / v \  Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 6.10)  Linux 2.6.21.1
  ^ ^   19:58:01 up 4 days 4:51 0 users load average: 0.06 0.11 0.04
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

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



Re: [PHP] Sockets as a module or a separate PHP CLI instance?

2007-05-02 Thread Oliver Block
Am Mittwoch, 2. Mai 2007 13:29 schrieb [EMAIL PROTECTED]:
 I need to do some socket work on a production machine that is constantly
 busy so I don't dare re-compile php. Anybody know if it's possible to load
 the socket functions dynamically, maybe as if they were in a module?

It's possible if it's possible to compile it as shared object. It is, as far 
as I know. 

--with-socket=shared

There might be some obstacles with threaded servers. I am not sure.

 Alternatively, would it be possible to compile PHP without apache and with
 sockets for command line use only?

--enable-cli

Regards,

Oliver

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



Re: [PHP] Sockets as a module or a separate PHP CLI instance?

2007-05-02 Thread Oliver Block
Am Mittwoch, 2. Mai 2007 14:36 schrieb Oliver Block:
 --with-socket=shared

Actually it should be --enable-sockets=shared

Regards,

Oliver

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



Re: [PHP] Deviation? Distribution? OT?

2007-05-02 Thread tedd

At 4:42 PM -0500 5/1/07, Richard Lynch wrote:

Little help here?


Richard:

Let me estate the problem. From your dB of things (the population), 
you're going to pull out the top 100 most popular items and then 
divide them into five groups using labels t1 through t5. Considering 
that it's css guy asking for this, he's probably making a tag 
cloud. They are kind of neat, you can look it up.


In any event, any population can be measured by it's distribution 
about it's mean (i.e., the average of the population).


Some distributions are gathered close to the mean while others are 
spread out from the mean. The measurement we use to describe this 
dispersion from the mean is standard deviation.


In your problem, I believe by using the standard deviation as a 
measure, you can break your population into divisions based how many 
fall with the first standard deviation, the second standard 
deviation, the third standard deviation, and so on.


Here's a demo I prepared for you:

http://sperling.com/a/stdev.php

It shows a simple population and it's standard deviation. From there 
you should be able see how you can use the standard deviation to do 
your divisions. I would be interested in reviewing your solution.


Cheers,

tedd

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

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



[PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Brian Dunning
I have a huge MySQL table, 2.1 million records, 200MB. Once a week I  
need to dump it in CSV format and zip the file.


This is not on my server, and it's in production, so I don't want to  
risk testing different methods and possibly hanging up their server  
for a period of time, so I wanted to seek advice here first to find  
what's the best way to proceed.


I can easily use PHP to query the table for the results I want and  
write a file line by line and then zip it, but I'm worried that might  
take too long and hang up the machine. The other way to go is some  
kind of sql dump command, which I guess would be faster, but not sure  
how much control I'd have over the exact format of the file. Any  
suggestions which way I should proceed? Not hanging up their server  
is my prime concern.


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



[PHP] RE: [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Jay Blanchard
[snip]
I have a huge MySQL table, 2.1 million records, 200MB. Once a week I  
need to dump it in CSV format and zip the file.

This is not on my server, and it's in production, so I don't want to  
risk testing different methods and possibly hanging up their server  
for a period of time, so I wanted to seek advice here first to find  
what's the best way to proceed.

I can easily use PHP to query the table for the results I want and  
write a file line by line and then zip it, but I'm worried that might  
take too long and hang up the machine. The other way to go is some  
kind of sql dump command, which I guess would be faster, but not sure  
how much control I'd have over the exact format of the file. Any  
suggestions which way I should proceed? Not hanging up their server  
is my prime concern.
[/snip]

SELECT * INTO OUTFILE /directory/myfile.csv
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY ''
  LINES TERMINATED BY '\n'
  FROM table;

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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Richard Davey

Brian Dunning wrote:

I have a huge MySQL table, 2.1 million records, 200MB. Once a week I 
need to dump it in CSV format and zip the file.


This is not on my server, and it's in production, so I don't want to 
risk testing different methods and possibly hanging up their server for 
a period of time, so I wanted to seek advice here first to find what's 
the best way to proceed.


I can easily use PHP to query the table for the results I want and write 
a file line by line and then zip it, but I'm worried that might take too 
long and hang up the machine. The other way to go is some kind of sql 
dump command, which I guess would be faster, but not sure how much 
control I'd have over the exact format of the file. Any suggestions 
which way I should proceed? Not hanging up their server is my prime 
concern.


If hogging their server is of prime concern then ideally you either need 
to (a) schedule down time for the site while the back-up happens, or (b) 
replicate the data to another MySQL server, and back-up that.


I can't see any reason why you need to bring PHP into the equation here, 
MySQL has more than enough native tools to do exactly what you need - 
and probably a butt-load faster too.


Cheers,

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

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

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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread David Giragosian

On 5/2/07, Richard Davey [EMAIL PROTECTED] wrote:


Brian Dunning wrote:

 I have a huge MySQL table, 2.1 million records, 200MB. Once a week I
 need to dump it in CSV format and zip the file.

 This is not on my server, and it's in production, so I don't want to
 risk testing different methods and possibly hanging up their server for
 a period of time, so I wanted to seek advice here first to find what's
 the best way to proceed.

 I can easily use PHP to query the table for the results I want and write
 a file line by line and then zip it, but I'm worried that might take too
 long and hang up the machine. The other way to go is some kind of sql
 dump command, which I guess would be faster, but not sure how much
 control I'd have over the exact format of the file. Any suggestions
 which way I should proceed? Not hanging up their server is my prime
 concern.

If hogging their server is of prime concern then ideally you either need
to (a) schedule down time for the site while the back-up happens, or (b)
replicate the data to another MySQL server, and back-up that.

I can't see any reason why you need to bring PHP into the equation here,
MySQL has more than enough native tools to do exactly what you need -
and probably a butt-load faster too.

Cheers,

Rich




Brian,

As a comparison, on a *nix master/slave configuration, I'm mysqldumping
nightly a database that's always growing and now is over a 1GB in size. The
dump takes about 20 seconds to finish. Assuming a linear relationship, your
200MB backup should only tie up the db server for around 5 seconds.

Bzipping the .sql file takes infinitiely longer, almost an hour, but a lower
compression ratio should take only 1/4 to 1/3 as long.

I'd say give some attention to the zip method you use.

HTH,

David


Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread clive



I'd say give some attention to the zip method you use.


or better yet rsync the file, send only what has changed.


--
Regards,

Clive.

Real Time Travel Connections


{No electrons were harmed in the creation, transmission or reading of 
this email. However, many were excited and some may well have enjoyed 
the experience.}


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



[PHP] Re: About resource of popen

2007-05-02 Thread Fernando chucre

Somebody? help me!!

:D

2007/4/30, Fernando chucre [EMAIL PROTECTED]:


Hello all,

I make a script for read and interprete the stdout of cmd `ip monitor`.
And I use signal_handler, the script is like this:
?
declare(ticks = 1);
pcntl_signal(SIGHUP,sig_handler,false);


$fh = popen('ip monitor','r');

while (!feof($fh))
{
$line = fgets($fh);
analize($line);
}

function analize($line) {  ...  } ;
function sig_handler($signo) { ... };
?

this script run in infine loop, or when to cmd 'ip monitor' exist. The
script ever whait the next line of 'ip monitor', ever. Then when I send the
signal SIGHUP to pid of script. In this point the instruction '$line =
fgets($fh);' is aborted and return false to $line. The $fh is modified and
the function feof($fh) return true and I have not access to $fh agaim. But
the kid process 'ip monitor' is not kill.

This is wanted?

--
Fernando Chure
PSL/CE





--
Fernando Chure
PSL/CE


[PHP] PHP's ldap_sasl_bind tries to authenticate with KRB5CCNAME other than the one provided by mod_auth_kerb

2007-05-02 Thread gil ran

Hi.

I am using Apache-2.2.2 with mod_auth_kerb-5.3, php-5.2.1,
openldap-2.3.27 cyrus-sasl-2.1.21 and heindal-0.7.2 on a
Linux-from-scratch based system.

The problem I'm presenting is probably a PHP issue or an Apache issue,
or a mod_auth_kerb issue. I could not understand which one causes the
problem.

I am trying to connect using SASL and GSSAPI to the LDAP server from a
PHP script that runs on the Apache server.

The script (in short) does the following:
 putenv(KRB5CCNAME= . $_SERVER['KRB5CCNAME']);
 echo getenv(KRB5CCNAME);
 system(klist);
 $ldapconn = ldap_connect(ldap://example.org;) || die(...);
 ldap_sasl_bind($ldapconn, NULL, NULL, GSSAPI) || die(...);

When I run the script manually from a shell that has a proper
KRB5CCNAME environment variable, both the system(klist) and the
ldap_sasl_bind(...) work as they should.

When I run `restart Apache' and then enter to the PHP page for the
first time both work as well. The KRB5CCNAME written is
/tmp/krb5ccname_apache_something

After that, each time I enter the page I get some other KRB5CCNAME
(other than the one I got before), the system(klist) command works
as it should, but ldap_sasl_bind returns Local error. In this case I
also get an error written to /var/log/auth. This error says that the
file /tmp/krb5ccname_apache_something could not be found (this is
the same something that was written by PHP after I restarted
Apache). This means that the authentication process tries to use the
previous file-name.

I added a debug print to PHP's ldap_sasl_bind function that prints
`getenv(KRB5CCNAME)' to Apache's error-log. The KRB5CCNAME written
to the error-log is the same as the one PHP outputs. Not the one
written to the auth log.

Why isn't the KRB5CCNAME variable passed on?
Which of the three (PHP, Apache, mod_auth_kerb) keeps the first KRB5CCNAME?
How do I cause the new KRB5CCNAME to be used for authentication?
Any ideas?

Thanks,
Gil Ran.

P.S.
I am not on the list, please cc me.

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



[PHP] excel macro into php

2007-05-02 Thread Anton Krall
Guys.. I have a problem and I was wondering if somebody with good php
knowledge could help.

I have this excel macro that converts number currency (mexican) into a
string and I was wondering if somebody could help translating it to php... 

Her eis the macro, if you could help, I would really appreciate it.

Thanks guys!

Function CantidadEnLetra(tyCantidad As Currency) As String
Dim lyCantidad As Currency, lyCentavos As Currency, lnDigito As Byte,
lnPrimerDigito As Byte, lnSegundoDigito As Byte, lnTercerDigito As Byte,
lcBloque As String, lnNumeroBloques As Byte, lnBloqueCero
tyCantidad = Round(tyCantidad, 2)
lyCantidad = Int(tyCantidad)
lyCentavos = (tyCantidad - lyCantidad) * 100
laUnidades = Array(UN, DOS, TRES, CUATRO, CINCO, SEIS, SIETE,
OCHO, NUEVE, DIEZ, ONCE, DOCE, TRECE, CATORCE, QUINCE,
DIESISEIS, DIESISIETE, DIESIOCHO, DIESINUEVE, VEINTE, VEINTIUN,
VEINTIDOS, VEINTITRES, VEINTICUATRO, VEINTICINCO, VEINTISEIS,
VEINTISIETE, VEINTIOCHO, VEINTINUEVE)
laDecenas = Array(DIEZ, VEINTE, TREINTA, CUARENTA, CINCUENTA,
SESENTA, SETENTA, OCHENTA, NOVENTA)
laCentenas = Array(CIENTO, DOSCIENTOS, TRESCIENTOS, CUATROCIENTOS,
QUINIENTOS, SEISCIENTOS, SETECIENTOS, OCHOCIENTOS, NOVECIENTOS)
lnNumeroBloques = 1
Do
lnPrimerDigito = 0
lnSegundoDigito = 0
lnTercerDigito = 0
lcBloque = 
lnBloqueCero = 0
For i = 1 To 3
lnDigito = lyCantidad Mod 10
If lnDigito  0 Then
Select Case i
Case 1
lcBloque =laUnidades(lnDigito - 1)
lnPrimerDigito = lnDigito
Case 2
If lnDigito = 2 Then
lcBloque =laUnidades((lnDigito * 10) + lnPrimerDigito - 1)
Else
lcBloque =laDecenas(lnDigito - 1)  IIf(lnPrimerDigito  0,  Y,
Null)  lcBloque
End If
lnSegundoDigito = lnDigito
Case 3
lcBloque =IIf(lnDigito = 1 And lnPrimerDigito = 0 And lnSegundoDigito
= 0, CIEN, laCentenas(lnDigito - 1))  lcBloque
lnTercerDigito = lnDigito
End Select
Else
lnBloqueCero = lnBloqueCero + 1
End If
lyCantidad = Int(lyCantidad / 10)
If lyCantidad = 0 Then
Exit For
End If
Next i
Select Case lnNumeroBloques
Case 1
CantidadEnLetra = lcBloque
Case 2
CantidadEnLetra = lcBloque  IIf(lnBloqueCero = 3, Null,  MIL) 
CantidadEnLetra
Case 3
CantidadEnLetra = lcBloque  IIf(lnPrimerDigito = 1 And lnSegundoDigito = 0
And lnTercerDigito = 0,  MILLON,  MILLONES)  CantidadEnLetra
End Select
lnNumeroBloques = lnNumeroBloques + 1
Loop Until lyCantidad = 0
CantidadEnLetra = (  CantidadEnLetra  IIf(tyCantidad  1,  PESOS , 
PESO )  Format(Str(lyCentavos), 00)  /100 M.N. )
End Function

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



[PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Rahul S. Johari

Ave,

Here¹s the thing, I¹ve got an Array which has it¹s own set of Keys =
Values. I¹m using foreach() to read the Keys = Values like this:

function pr1($var) {
foreach ($var as $k = $v) {
echo ³$k = $v²;
}  

I need to INSERT the Values from this array into a  mySQL table. The problem
is, There is other data that is going into the same row of that mySQL Table
as well. 

So I have to basically insert 3 fields and then the rest of values I have to
insert using this Array. In other words, this is what I have to do:

INSERT into table  (f1, f2, f3, f4, f5) VALUES (Œ$1¹, Œ$2¹, Œ$3¹, //and the
rest of the values from from the $v Values from that Array $var.

I¹m not able to formulate a code to do this. Any help would be really
appreciated. 

Thanks.

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

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

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








RE: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Brad Fuller
Rahul S. Johari wrote:
 Ave,
 
 Here¹s the thing, I¹ve got an Array which has it¹s own set of
 Keys = Values. I¹m using foreach() to read the Keys = Values like
 this: 
 
 function pr1($var) {
 foreach ($var as $k = $v) {
 echo ³$k = $v²;
 }
 
 I need to INSERT the Values from this array into a  mySQL
 table. The problem is, There is other data that is going into
 the same row of that mySQL Table as well.
 
 So I have to basically insert 3 fields and then the rest of
 values I have to insert using this Array. In other words, this is
 what I have to do: 
 
 INSERT into table  (f1, f2, f3, f4, f5) VALUES (Œ$1¹, Œ$2¹,
 Œ$3¹, //and the rest of the values from from the $v Values from that
 Array $var. 
 
 I¹m not able to formulate a code to do this. Any help would be really
 appreciated. 
 
 Thanks.
 
 ~~~
 Rahul Sitaram Johari
 CEO, Twenty Four Seventy Nine Inc.
 
 W: http://www.rahulsjohari.com
 E: [EMAIL PROTECTED]
 
 ³I morti non sono piu soli ... The dead are no longer lonely²


$sql = INSERT INTO table (f1, f2, f3, . implode(,, array_keys($pr1)) .)
  VALUES ('abc', '123', '456', . implode(,, array_values($pr1))
.);

HTH,

Brad

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



Re: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread David Giragosian

On 5/2/07, Rahul S. Johari [EMAIL PROTECTED] wrote:



Ave,

Here¹s the thing, I¹ve got an Array which has it¹s own set of Keys =
Values. I¹m using foreach() to read the Keys = Values like this:

   function pr1($var) {
   foreach ($var as $k = $v) {
   echo ³$k = $v²;
   }

I need to INSERT the Values from this array into a  mySQL table. The
problem
is, There is other data that is going into the same row of that mySQL
Table
as well.

So I have to basically insert 3 fields and then the rest of values I have
to
insert using this Array. In other words, this is what I have to do:

INSERT into table  (f1, f2, f3, f4, f5) VALUES (Œ$1¹, Œ$2¹, Œ$3¹, //and
the
rest of the values from from the $v Values from that Array $var.

I¹m not able to formulate a code to do this. Any help would be really
appreciated.




Either gather all the data together first, and then do an insert, or do an
insert on the 1st part, then update the record with the remaining data with
a where clause (Use last_insert_id() to track a primary key, or pass some
unique identifier from the insert to the update query). Personally, I'd find
a way to gather all the data first and do it all with one insert.

David


[PHP] Re: [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Colin Guthrie
clive wrote:
 
 I'd say give some attention to the zip method you use.
 
 or better yet rsync the file, send only what has changed.

Good advice but may not work as well with extended insert syntax which
results in smaller dump files and much faster import too.

I guess with CSV it could work well tho' (my mind is stuck in mysql dump
output mode ;))

COl

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



RE: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Jim Moseby
 
 $sql = INSERT INTO table (f1, f2, f3, . implode(,, 
 array_keys($pr1)) .)
 VALUES ('abc', '123', '456', . implode(,, 
 array_values($pr1))
 .);
 
 HTH,
 
 Brad


Might not work if the array values need to be enclosed in quotes.  I would
build the query string in a foreach loop and execute the query afterwards.

JM

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



Re: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Rahul Sitaram Johari

Ave,

I was just about to post when I saw your message. I think what you're saying
is exactly what is happening. The values have Spaces and stuff so Quotes are
Required - cannot have values not enclosed in Quotes. Other then that it was
actually working.

Is there a way to enclose in Quotes using the implode statement?



On 5/2/07 12:03 PM, Jim Moseby [EMAIL PROTECTED] wrote:

 
 $sql = INSERT INTO table (f1, f2, f3, . implode(,,
 array_keys($pr1)) .)
  VALUES ('abc', '123', '456', . implode(,,
 array_values($pr1))
 .);
 
 HTH,
 
 Brad
 
 
 Might not work if the array values need to be enclosed in quotes.  I would
 build the query string in a foreach loop and execute the query afterwards.
 
 JM

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



[PHP] Re: Split string

2007-05-02 Thread Al

Look at split() and explode().

Lester Caine wrote:
Can someone with a few more working grey cells prompt me with the 
correct command to split a string.


The entered data is names, but I need to split the text up to the first 
space or comma into one string, and the rest of the string into a 
second. It's the 'first either space or comma' that eludes me at the 
moment :(


In know it's probably obvious, but it always is when you know the answer.



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



RE: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Brad Fuller
Jim Moseby wrote:
 $sql = INSERT INTO table (f1, f2, f3, . implode(,,
array_keys($pr1)) .) VALUES ('abc', '123', '456', . implode(,,
 array_values($pr1))
 .);
 
 HTH,
 
 Brad
 
 
 Might not work if the array values need to be enclosed in
 quotes.  I would build the query string in a foreach loop and execute
 the query afterwards. 
 
 JM

Good point, Jim.  I just realized that.  I actually use this method in one
of my scripts; in my case all of the fields are varchar and the code below
works perfectly.  This is updated to quote all values.

$sql = INSERT INTO coreg_lead (.implode(,, array_keys($dbFields)).)
VALUES ('.implode(',', array_values($dbFields)).');

-Brad

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



Re: [PHP] INSERT Array Values into mySQL Table - SOLVED!

2007-05-02 Thread Rahul Sitaram Johari

WORKS Like A Charm!! :)

Thanks.


On 5/2/07 12:14 PM, Brad Fuller [EMAIL PROTECTED] wrote:

 Jim Moseby wrote:
 $sql = INSERT INTO table (f1, f2, f3, . implode(,,
  array_keys($pr1)) .) VALUES ('abc', '123', '456', . implode(,,
 array_values($pr1))
 .);
 
 HTH,
 
 Brad
 
 
 Might not work if the array values need to be enclosed in
 quotes.  I would build the query string in a foreach loop and execute
 the query afterwards.
 
 JM
 
 Good point, Jim.  I just realized that.  I actually use this method in one
 of my scripts; in my case all of the fields are varchar and the code below
 works perfectly.  This is updated to quote all values.
 
 $sql = INSERT INTO coreg_lead (.implode(,, array_keys($dbFields)).)
 VALUES ('.implode(',', array_values($dbFields)).');
 
 -Brad

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



Re: [PHP] PHP Command line script

2007-05-02 Thread Nathaniel Hall

Greg Donald wrote:


On 5/1/07, Nathaniel Hall [EMAIL PROTECTED] wrote:
 I am attempting to run a script that will run from the command line
 nightly to update a field in a database.  I already created a script
 that would access the database and insert most of the information when a
 webpage is visited and I had no problems with it.  The command line
 script appears to fail on the prepare.  I have echo'ed the SQL statement
 to the screen, copied it, and run it on the MySQL server with no
 problems.  Any ideas?

 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
 any further than here, even when hard coding the information.
 $logout-bind_param(s, 
date('m\-d\-Y\TH\:i\:s'));

 $logout-execute();
 $logout-close();
 }
 }
 $mysqli-close();
 ?


Add full error reporting, then make sure you can see the errors, then
test to see if you have the mysqli extension:

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
ini_set( 'log_errors', 1 );

if( !in_array( 'mysqli', get_loaded_extensions() ) )
{
die( 'no mysqli found' );
}


I get no errors and I have verified that mysqli is loaded.


Also, why do you need to escape the dashes in the date() calls?

 php -r 'echo date(Y-m-d);'
2007-05-01


Habit.

--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security

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



[PHP] Bounce composition

2007-05-02 Thread Richard Lynch
Does anybody have or know of a good simple PHP script that can take an
email as an input, and compose a Bounce email as output?

I need something that does just that, without a huge framework or a
zillion other features...

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



[PHP] Discussion of bug #39062

2007-05-02 Thread Bill Moran

http://bugs.php.net/bug.php?id=39062

I'm requesting that this bug be reopened and reconsidered.

I'm completely befuddled by the handling of this bug.  The message text
suggests a workaround, then the bug is marked bogus.  If the bug is
bogus, why is there a workaround required?

Additionally, the suggested workaround doesn't even work.  dechex()
reliably returns 64 hex bits for 64-bit numbers and 32 hex bits for
32-bit numbers, which still results in incorrect comparisons, for
example f34c690a != f34c690a.

-- 
Bill Moran
Collaborative Fusion Inc.
http://people.collaborativefusion.com/~wmoran/

[EMAIL PROTECTED]
Phone: 412-422-3463x4023

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



Re: [PHP] Discussion of bug #39062

2007-05-02 Thread Robert Cummings
On Wed, 2007-05-02 at 14:14 -0400, Bill Moran wrote:
 http://bugs.php.net/bug.php?id=39062
 
 I'm requesting that this bug be reopened and reconsidered.
 
 I'm completely befuddled by the handling of this bug.  The message text
 suggests a workaround, then the bug is marked bogus.  If the bug is
 bogus, why is there a workaround required?
 
 Additionally, the suggested workaround doesn't even work.  dechex()
 reliably returns 64 hex bits for 64-bit numbers and 32 hex bits for
 32-bit numbers, which still results in incorrect comparisons, for
 example f34c690a != f34c690a.

Sounds like you have everything you need to create a wrapper function to
produce exactly what YOU need :)

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] Discussion of bug #39062

2007-05-02 Thread Daevid Vincent
While I'm not using this particular function, I do agree with you, it's
kinda sucky that they just dismissed their broken-ass method. It should
return -2G..2G as advertised and as all other POSIX systems do. And you are
also correct about the work around that is erroneous too.

IMHO, this is a genuine bug and needs a genuine fix. 

 -Original Message-
 From: Bill Moran [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, May 02, 2007 11:14 AM
 To: php-general@lists.php.net
 Subject: [PHP] Discussion of bug #39062
 
 
 http://bugs.php.net/bug.php?id=39062
 
 I'm requesting that this bug be reopened and reconsidered.
 
 I'm completely befuddled by the handling of this bug.  The 
 message text
 suggests a workaround, then the bug is marked bogus.  If the bug is
 bogus, why is there a workaround required?
 
 Additionally, the suggested workaround doesn't even work.  dechex()
 reliably returns 64 hex bits for 64-bit numbers and 32 hex bits for
 32-bit numbers, which still results in incorrect comparisons, for
 example f34c690a != f34c690a.
 
 -- 
 Bill Moran
 Collaborative Fusion Inc.
 http://people.collaborativefusion.com/~wmoran/
 
 [EMAIL PROTECTED]
 Phone: 412-422-3463x4023
 
 -- 
 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] INSERT Array Values into mySQL Table

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 11:03 am, Jim Moseby wrote:

 $sql = INSERT INTO table (f1, f2, f3, . implode(,,
 array_keys($pr1)) .)
VALUES ('abc', '123', '456', . implode(,,
 array_values($pr1))
 .);

 HTH,

 Brad


 Might not work if the array values need to be enclosed in quotes.  I
 would
 build the query string in a foreach loop and execute the query
 afterwards.

It's pretty trivial to convert to:

VALUE ('abc', '123', '456', ' . implode(',', $array_values($pr1)) .
');

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

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



Re: [PHP] INSERT Array Values into mySQL Table

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 10:42 am, Rahul S. Johari wrote:
 Here¹s the thing, I¹ve got an Array which has it¹s own set of Keys =
 Values. I¹m using foreach() to read the Keys = Values like this:


//note added arguments!
 function pr1($var, $var2, $var3) {
 foreach ($var as $k = $v) {
 echo ³$k = $v²;

echo $var2[$k] $var3[$k];

//DID YOU USE mysql_real_escape_string YET?!
$query = insert into whatever (v1, v2, v3) ;
$query .=  values('$v', '$var2[$k]', '$var3[$k]') ;

Or maybe $v is an array itself?

//perhaps you want:
list($v1, $v2, $v3) = each($v);


 }

 I need to INSERT the Values from this array into a  mySQL table. The
 problem
 is, There is other data that is going into the same row of that mySQL
 Table
 as well.

 So I have to basically insert 3 fields and then the rest of values I
 have to
 insert using this Array. In other words, this is what I have to do:

 INSERT into table  (f1, f2, f3, f4, f5) VALUES (Œ$1¹, Œ$2¹, Œ$3¹,
 //and the
 rest of the values from from the $v Values from that Array $var.

 I¹m not able to formulate a code to do this. Any help would be really
 appreciated.

 Thanks.

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

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

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









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

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



Re: [PHP] PHP's ldap_sasl_bind tries to authenticate with KRB5CCNAME other than the one provided by mod_auth_kerb

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 9:41 am, gil ran wrote:
 I am using Apache-2.2.2 with mod_auth_kerb-5.3, php-5.2.1,
 openldap-2.3.27 cyrus-sasl-2.1.21 and heindal-0.7.2 on a
 Linux-from-scratch based system.

 The problem I'm presenting is probably a PHP issue or an Apache issue,
 or a mod_auth_kerb issue. I could not understand which one causes the
 problem.

 I am trying to connect using SASL and GSSAPI to the LDAP server from a
 PHP script that runs on the Apache server.

 The script (in short) does the following:
   putenv(KRB5CCNAME= . $_SERVER['KRB5CCNAME']);
   echo getenv(KRB5CCNAME);
   system(klist);

Always use 'exec' instead, and ALWAYS get the output and the error
code and ALWAYS ALWAYS ALWAYS check the error code!

   $ldapconn = ldap_connect(ldap://example.org;) || die(...);
   ldap_sasl_bind($ldapconn, NULL, NULL, GSSAPI) || die(...);

 When I run the script manually from a shell that has a proper
 KRB5CCNAME environment variable, both the system(klist) and the
 ldap_sasl_bind(...) work as they should.

When you run the script manually from a shell, you are probably NOT
the same User as PHP runs as, and you are probably NOT using the same
shell either, and you therefore almost certainly do NOT have the same
environment for your test as for Reality.

This is like stunt-driving a car on a Closed Course with a
Professional Driver, and then pretending that it's safe to do that
same stunt on a busy city street... :-)

99.9% of the time, this problem boils down to:
paths and permissions

Use a FULL PATH for any file/program in your exec call:
NOT klist
/usr/bin/klist
/usr/local/bin/klist
/sharedhost/example.com/usr/local/i/compiled/it/myself/bin/klist

NOT somefile.txt
/full/path/to/wherever/it/lives/somefile.txt


 When I run `restart Apache' and then enter to the PHP page for the
 first time both work as well. The KRB5CCNAME written is
 /tmp/krb5ccname_apache_something

I dunno what klist does, nor what any of the KRB stuff is, but if you
want to preserve this KRB thingie from page to page, it looks like you
will need to do more than just run 'klist'...

You'll need to store the setting somewhere, transmit that storage
location through the stateless HTTP protocol (just like
GET/POST/COOKIE is used) and then retrieve it if it's already been
stored, or make a new one, as appropriate for whatever you are trying
to do, which I also don't really understand, but there it is.

 After that, each time I enter the page I get some other KRB5CCNAME
 (other than the one I got before), the system(klist) command works
 as it should, but ldap_sasl_bind returns Local error. In this case I
 also get an error written to /var/log/auth. This error says that the
 file /tmp/krb5ccname_apache_something could not be found (this is
 the same something that was written by PHP after I restarted
 Apache). This means that the authentication process tries to use the
 previous file-name.

See above.

 I added a debug print to PHP's ldap_sasl_bind function that prints
 `getenv(KRB5CCNAME)' to Apache's error-log. The KRB5CCNAME written
 to the error-log is the same as the one PHP outputs. Not the one
 written to the auth log.

 Why isn't the KRB5CCNAME variable passed on?

Why should it be passed on?

Each run of your script is a totally separate process, and if you
have multiple Apache children, they each have their own process.

So unless you've got some magic wand to get them all to share (e.g., a
cross-process storage/communcation) they are not going to share.

 Which of the three (PHP, Apache, mod_auth_kerb) keeps the first
 KRB5CCNAME?

Yes.

:-)

If you are running PHP as CGI, it will never have the same KRB twice,
I suspect.

If you run PHP as Apache module, each Apache child and the related PHP
environment could easily keep its own KRB, I suspect.

I got no idea whatsoever what the kerb thing is doing, but as a
mod_xxx, it is also tied to the Apache child process, of which there
might be HUNDREDS.

If you are setting the ENV in the Apache startup with something in
httpd.conf or your Apache startup script, that would maybe share the
KRB across all children, but just setting it with PHP script won't
touch other children.

 How do I cause the new KRB5CCNAME to be used for authentication?

Hopefully I've outlined the issues enough above for you to know the
answer, even though I have no idea what the answer really is...

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

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



Re: [PHP] Discussion of bug #39062

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 1:14 pm, Bill Moran wrote:

 http://bugs.php.net/bug.php?id=39062

 I'm requesting that this bug be reopened and reconsidered.

 I'm completely befuddled by the handling of this bug.  The message
 text
 suggests a workaround, then the bug is marked bogus.  If the bug is
 bogus, why is there a workaround required?

 Additionally, the suggested workaround doesn't even work.  dechex()
 reliably returns 64 hex bits for 64-bit numbers and 32 hex bits for
 32-bit numbers, which still results in incorrect comparisons, for
 example f34c690a != f34c690a.

This discussion may be better placed on Internals where the people
who make these decisions hang out more...

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

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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 8:54 am, Brian Dunning wrote:
 I have a huge MySQL table, 2.1 million records, 200MB. Once a week I
 need to dump it in CSV format and zip the file.

You could run mysql_dump once by hand and test just how bad it is, and
be ready to kill -9 it if the server gets hurt...

But, really, as a long-term SAFE solution, the best bet would probably
be do set up a master/slave replication in MySQL, and have the *slave*
be something non-production that you mysql_dump.

There are some caveats to the replication, such as making SURE you
have enough hard drive space for the log files, and enough bandwidth
that the log files never grow too large.

But once you get that working well, you can pretty much do whatever
you want to the slave and not risk the master being bogged down.

This is also a VERY common way to set up a reporting server, so your
marketing weenies can write the ad hoc queries they love that tend to
bring down a server... :-v

 I can easily use PHP to query the table for the results I want and
 write a file line by line and then zip it, but I'm worried that might
 take too long and hang up the machine. The other way to go is some
 kind of sql dump command, which I guess would be faster, but not sure
 how much control I'd have over the exact format of the file. Any
 suggestions which way I should proceed? Not hanging up their server
 is my prime concern.

If you can't do a replication setup, or the budget is ridiculously
low, running a PHP script with a sleep call and a set_time_limit to
make sure it never dies, you can slowly and surely dump out a few
records at a time.

The risk there is inconsistencies in your dump, for related keys
between tables...

It will *NOT* be faster than mysql_dump, ever, by any means, almost
for sure, but you'll be able to control how much it pounds the server
more easily.

mysql_dump *may* have some kind of command line flag to limit the
resources it consumes so you don't drag down the DB...

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

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



[PHP] MySQL change-tracking

2007-05-02 Thread Richard Lynch
I have this simple database and I'm going to have a handful of people
editing it...

I'd like to track each and every edit with username, and, ideally,
provide myself an easy Undo if I decide [bleep] is an idiot and
shouldn't have done that.

Now, I'm not real concerned about the relational foreign key aspect
here, and I'd like to keep this as simple as possible...

I've considered doing a dump and putting the output into subversion,
even...

I realize there may be some nifty MySQL tool that does this, so I'll
be researching that shortly, but I'm wondering if there's a nifty
change-management php package out there that I should check out.

The users are currently slated to be logging in via HTTP Basic
Authentication, but I could change that, I guess.

K.I.S.S. is definitely the motto around here -- If it takes more than
a day or two to figure out, install, and implement; then forget it, as
I can just hack something together myself in that time-frame.

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

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



Re: [PHP] Sockets as a module or a separate PHP CLI instance?

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 6:29 am, [EMAIL PROTECTED] wrote:
 I need to do some socket work on a production machine that is
 constantly
 busy so I don't dare re-compile php. Anybody know if it's possible to
 load
 the socket functions dynamically, maybe as if they were in a module?

If you can do --with-sockets=shared, for the configure, you should end
up with a sockets.so file that you can then use http://php.net/dl to
load into your scripts that need sockets...

At least, *some* extensions this works...

 Alternatively, would it be possible to compile PHP without apache and
 with
 sockets for command line use only?

Definitely.

Just compile it as CLI or CGI, without the --with-apxs or --with-apxs2
or whatever pulls in Apache.

 If I do that I would like to give
 the
 resulting object a different name than PHP because I do have some cmd
 line
 pgms running on the machine. Is that difficult?

Then don't do 'make install' but just copy the bin/php over to
/usr/local/bin/php-with-sockets

Then you can do php-with-sockets -q whatever.php to run that one
special PHP binary.

Alternatively, you can download the PHP source to a whole new fresh
directory, compile it for CLI, and then leave it there, and use:

/path/to/php/src/php/bin/php -q whatever.php

so that you are running the special php binary from that source
directory instead of the usual one in /usr/local/bin (or wherever
yours lives)

I did that for a CVS version when I needed a patched PHP on a shared
host, and it worked pretty well for a cron job.

It would be kind of cumbersome for something you wanted to run by hand
from the shell a lot, but for a set it and forget it cron job, it was
fine for me.

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

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



Re: [PHP] Split string

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 3:55 am, Lester Caine wrote:
 Can someone with a few more working grey cells prompt me with the
 correct
 command to split a string.

 The entered data is names, but I need to split the text up to the
 first space
 or comma into one string, and the rest of the string into a second.
 It's the
 'first either space or comma' that eludes me at the moment :(

 In know it's probably obvious, but it always is when you know the
 answer.

One of these should have an example to get you where you need to be:
http://php.net/split
http://php.net/preg_split

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

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



Re: [PHP] Bounce composition

2007-05-02 Thread Oliver Block
Am Mittwoch, 2. Mai 2007 20:11 schrieb Richard Lynch:
 Does anybody have or know of a good simple PHP script that can take an
 email as an input, and compose a Bounce email as output?

 I need something that does just that, without a huge framework or a
 zillion other features...

please try this:

$env['from'] = '[EMAIL PROTECTED]';
$env['to'] = '[EMAIL PROTECTED]';
$env['remail'] = imap_fetchheader($stream, $msgno);

$part0['contents.data'] = imap_body($stream, $msgno);
$body[0] = $part0;

$bounce_msg = imap_mail_compose($env, $body);

Not you should get rid of the 'Received-' headers.

I did not test it. If something goes wrong, please post again.

Regards,

Oliver

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



Re: [PHP] Split string

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 4:55 am, Lester Caine wrote:
 Fredrik Thunberg wrote:
 Lester Caine skrev:
 Can someone with a few more working grey cells prompt me with the
 correct command to split a string.

 The entered data is names, but I need to split the text up to the
 first space or comma into one string, and the rest of the string
 into
 a second. It's the 'first either space or comma' that eludes me at
 the
 moment :(

 In know it's probably obvious, but it always is when you know the
 answer.

 $myString = John Doe;

 $pos = strpos($myString,  )  strpos($myString, ,) ?
 strpos($myString,  ) : strpos($myString, ,);

 $part1 = substr($myString, 0, $pos);
 $part2 = substr($myString, $pos);

 I'm glad I asked now, that is a lot nicer than trying to get the
 preg_split
 thing working :)

Hnmmm.  Okay, I'll take a shot at it:

$answer = preg_split('|[, ]|', $myString);
var_dump($answer);

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

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



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 2:17 am, Todd Cary wrote:
 Some shared servers do not allow the creation of a file, so I am
 looking for a way to take the results of a query (MySQL), create
 a CSV output and have it in a sendable format for the user
 without creating a file.


$result = mysql_query(select * from something);

$output = fopen('php://output', 'w') or die(I messed up the php://
bit);

header(Content-type: application/octet-stream); //force download
while ($row = mysql_fetch_row($result)){
  fputcsv($output, $row);
}

//Look ma, no file!

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

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



Re: [PHP] Deviation? Distribution? OT?

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 4:48 pm, Daniel Brown wrote:
 I don't think I'm quite following why you wouldn't just want to
 break it
 up into groups of 20

Because in the real world, it's not an even distribution of popularity.

There are only 1 or 2 Legends, and a handful of Rock Stars, and a
couple dozen Household Names, and then lots and lots of Famous in the
Top 100.

I need the relative popularity as a weighted distribution thingie,
like that.

I don't know what the actual scores will be, as they will change over
time with more users -- but I know the relativistic popularity is not
an even distribution curve.

Damn I wish I remembered this crap from 20 years ago better.

I so do *not* want to run through those textbooks again.  I hated it
the first time around... :-)

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

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



Re: [PHP] Deviation? Distribution? OT?

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 7:55 am, tedd wrote:
 Let me estate the problem. From your dB of things (the population),
 you're going to pull out the top 100 most popular items and then
 divide them into five groups using labels t1 through t5. Considering
 that it's css guy asking for this, he's probably making a tag
 cloud. They are kind of neat, you can look it up.

It is DEFINITELY a tag cloud.

That's precisely what it is, actually...

Now if I can just see how to relate your sample web page to what I'm
looking for, I'm all set... :-)

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

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



Re: [PHP] PHP Command line script

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 3:13 pm, Nathaniel Hall wrote:
 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE
 `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not
 go
 any further than here, even when hard coding the information.
 $logout-bind_param(s,
 date('m\-d\-Y\TH\:i\:s'));
 $logout-execute();
 $logout-close();
 }

//ALWAYS do your error-checking!!!
  else{
die(mysqli_error());
  }

//You may want to put the query in $query so you can print that
//as part of the 'die' output

 }
 $mysqli-close();
 ?

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

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



Re: [PHP] resize image and store it to DB

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 5:54 am, Alain Roger wrote:
 else // both $width and $height are smaller than max, so we need to
 zoom

Zooming an image is RARELY satisfactory in appearance...

I'd say just leave it alone, personally.

 $escaped = pg_escape_bytea($thumb); // does not work and it's normal

 $thumb is an image, so ho can i make it useful for pg_escape_bytea
 function
 ?

$thumb isn't the actual JPEG image.

It's just a PHP resource number, pointing to the image.

So, essentially, you are cramming the number 3 (or 2 or 4 or
whatever) into PostgreSQL.

You would need to do something not unlike:

ob_start();
imagejpeg($thumb);
$image = ob_get_contents();
ob_end_clean();
$escaped = pg_escape_bytea($image);

//Insert obligatory don't store images in DB flame-war here :-)

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

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



Re: [PHP] newbie needs help

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 3:37 pm, Ben Clapp wrote:
 I am new to PHP programming and need some help. I have an image that i
 have show up each May for the month with $mymonth = date(m,
 mktime()),
 but i want to set up a date range for it to show up. Ex. 4-13 to 5-13
 each year. How can I do that? Any help would be great.

$now = time();
//leave the year off for 'annual' calculations:
if (mktime(1, 0, 0, 4, 13) = $time  $time = mktime(1, 0, 0, 5, 13)){
  //do something to show your May image.
}
else{
  //show the usual image, or nothing, or whatever
}

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

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



RE: [PHP] What does mean?

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 6:33 pm, Daevid Vincent wrote:
 echo BROWSER:  . $_SERVER['HTTP_USER_AGENT'] . \n;

 I've always had problems with heredoc when I try using arrays like
 that. I
 will either pull them into a straight $foo, or use the ${} thing.

It probably won't do 2-D arrays, but 1-D should be fine.

 echo EOF
 BROWSER: $_SERVER[HTTP_USER_AGENT]
 EOF;

 Isn't that form (sans quote marks) deprecated and frowned upon?

I think it was for a brief period, but the masses revolted and said
they LIKED the non-apostrophe embedded arrays with no extra syntax...

The preceding is a gross-oversimplifaction and biased interpretation
of historical events in the PHP Community.  Apologies to all involved.

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

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



Re: [PHP] What does mean?

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 7:19 pm, Richard Davey wrote:
 Greg Donald wrote:

 On 4/30/07, Daevid Vincent [EMAIL PROTECTED] wrote:
  echo EOF
  BROWSER: $_SERVER[HTTP_USER_AGENT]
  EOF;

 Isn't that form (sans quote marks) deprecated and frowned upon?

 ?php

 error_reporting( E_ALL );

 echo EOF
 BROWSER: $_SERVER[HTTP_USER_AGENT]
 EOF;

 Why would cleaner, perfectly error free code be frowned upon?

 I'm not dissing heredoc syntax, it has its uses (now and again) but
 it's
 far from clean, especially when embedded deep in classes - the major
 cause being the delimeters insistance on being at the very start of
 the
 line. It's just *not* pretty IMHO. Certainly not girl code [1]

 The frowning surely would be at the mixing of logic and presentation,
 regardless how that mix happens (heredoc, echo, jumping in and out of
 PHP tags, sprintf, etc).

There's some folks that take this presentation/logic separation ideal
a bit TOO far, imho...

I mean, some of the logic is all ABOUT presentation, and there's no
actual business/algorithm to it.

Call it GUI logic.  (Or even girl-logic, if you want to push the
metaphor above way too far...) :-)

Choosing heredoc or echo or sprintf in a rigid
thou-shalt-always-use-this fashion as some do often ends up with what
I consider code cruft.

You end up with:

sprintf(%d, $d);

or

echo EOFOO
Foo!
EOFOO;

and so on, which are just plain silly, really...

I tend to use the right weapon (imho) for the task at hand, and freely
inter-mingle MINOR calculations and GUI-logic in the HTML.

But any heavy lifting or algorithm/business logic goes way at the top
before any HTML output.

Works okay for me, for most of a decade now, but drives some folks
nuts.  Oh well.  They don't like my code, they don't have to steal it.
:-)

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

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



Re: [PHP] What does mean?

2007-05-02 Thread Richard Lynch


On Mon, April 30, 2007 7:44 pm, Greg Donald wrote:
 On 4/30/07, Greg Donald [EMAIL PROTECTED] wrote:
 All parts of a heredoc statement do not have to be right justified,
 only the closing line.

 I meant my other right, the one on my left.  Sorry.

You don't *HAVE* to left-justify the rest either, but, really, the
results are not the same if you don't...

?php
  //pretend I have LOTS of code here with proper indentation:
if ($foo){
   $output1 = EOFOO
This is a test.
This is only a test.
EOFOO;
   $output2 = EOBAR;
 This is a test.
 This is only a test.
   EOBAR; //I wish!
 }
?

Now, if you want to put $output1 and $output2 into an email and dash
it off to somebody, you ain't gonna get quite the same results with
them both...

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

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



Re: [PHP] What does mean?

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 3:41 pm, Micky Hulse wrote:
 Daniel Brown wrote:
Actually, that should be directed at the OP who said that.  I was
 able
 to bring up the heredoc, too.  ;-P

 Ooops! Sorry Daniel, I meant to reply to Nick... My mistake. :(

Cool!

They fixed
http://php.net/
to go to the strings page!

Just wish it jumped to the anchor as well... :-)

I'm greedy. :-) :-) :-)

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

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



Re: [PHP] What does mean?

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 7:18 pm, Paul Novitski wrote:
 When I first started using PHP I thought that each heredoc label had
 to be unique.  Turns out that's not true, and now I use the simple
 shorthand:

 $sResult = _
 Some text.
 _;

I suspect earlier versions of PHP required unique labels...

At least, I *still* thought they had to be unique... :-)

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

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



Re: [PHP] What does mean?

2007-05-02 Thread Daniel Brown

On 5/2/07, Richard Lynch [EMAIL PROTECTED] wrote:


Cool!

They fixed
http://php.net/
to go to the strings page!

Just wish it jumped to the anchor as well... :-)

I'm greedy. :-) :-) :-)



I'll say you are!  Next you'll want all of the links on the site to point to
the correct spots!

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Re: [PHP] What does mean?

2007-05-02 Thread Daniel Brown

   No, to my knowledge, even PHP3 (I honestly don't remember if it was in
PHP/FI, but I don't think so) allowed you to use the same name for multiple
heredoc's.  It just works like the for/next concept in BASIC for this =
this to that (do something), next this.  Meaning that as soon as the
condition is met (this = that), release this.

   And as far as I know, Perl is the same, as are any other languages where
heredoc syntax is present.

   That's kind of dumbing it down to the point of changing it, perhaps, but
I hope I'm at least speaking English.


On 5/2/07, Richard Lynch [EMAIL PROTECTED] wrote:


On Mon, April 30, 2007 7:18 pm, Paul Novitski wrote:
 When I first started using PHP I thought that each heredoc label had
 to be unique.  Turns out that's not true, and now I use the simple
 shorthand:

 $sResult = _
 Some text.
 _;

I suspect earlier versions of PHP required unique labels...

At least, I *still* thought they had to be unique... :-)

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

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





--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Re: [PHP] Re: What does mean?

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 12:55 pm, Robert Cummings wrote:
 Are there perhaps editors that would DISPLAY multi-line quoted
 strings
 indented to the correct level without inserting extra spaces? Some
 editors wrap lines to the correct level, which is also much more
 readable, so what I'm thinking of is a bit similar to that.

 Then you'd have an editor that presents something other than what is
 actually there. Go see Microsoft, I'm sure they create rubbish like
 that.

All editors display something other than what is actually there, to
some degree... :-)

That said...

The problem with the editor auto-indenting lines that aren't indented
is what to do with lines that ARE indented...

True Source:
$email = EOM
  This is a paragraph that has been indented and
hard line-wrapped with something not unlike:
http://php.net/wordwrap
http://php.net/wordwrap
and has had URLs embedded in ways to make sure ALL
email clients will present at least ONE clickable link,
even the dreaded AOL 4.0
  Yes, I still have code that is hanging around
from when AOL 4.0 was new.
  Sorry.
EOM;

So what would your nifty editor do with that?

Indent it to match PHP indenting, and then add the whitespace of the
actual message?

I think that might work well, though lead to a lot of un-readable
right-shifted long text lines instead of the ugly indentation.

One think you could consider to avoid the ugliness is to put the
heredoc into a one-use function or in an incldue file that doesn't
have enough indenting for it to look ugly in the first place. :-)

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

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



Re: [PHP] [X-POST] Fastest way to dump this huge table

2007-05-02 Thread Brian Dunning
Thanks to everyone who answered, think I've got enough info now to  
handle it.  :)


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



RE: [PHP] sloppy use of constants as strings. WAS: What does mean?

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 9:05 pm, Daevid Vincent wrote:
   echo EOF
   BROWSER: $_SERVER[HTTP_USER_AGENT]
   EOF;
 
  Isn't that form (sans quote marks) deprecated and frowned upon?

 ?php

 error_reporting( E_ALL );

 echo EOF
 BROWSER: $_SERVER[HTTP_USER_AGENT]
 EOF;

 Why would cleaner, perfectly error free code be frowned upon?

 http://us2.php.net/manual/en/language.types.array.php
 A key may be either an integer or a string. If a key is the standard
 representation of an integer, it will be interpreted as such (i.e. 8
 will
 be interpreted as 8, while 08 will be interpreted as 08).

 I was always under the impression that using:

   $_SERVER[HTTP_USER_AGENT] or $foo[myindex]

 Was bad compared to the proper way of:

   $_SERVER['HTTP_USER_AGENT'] or $foo['myindex']

Those *ARE* bad, but they aren't embedded in double-quotes, nor
heredoc, which are entirely different environments.

Those are raw PHP syntax strings, with no delimiters to set them off
as string

 Just like it's:

   define('MYTHING', true);

 not

   define(MYTHING, true);

Same exact thing.

 (again, note the ' marks)

 http://us2.php.net/manual/en/function.define.php
 http://us2.php.net/manual/en/language.constants.php

 If you use an undefined constant, PHP assumes that you mean the name
 of the
 constant itself, just as if you called it as a string (CONSTANT vs
 CONSTANT). An error of level E_NOTICE will be issued when this
 happens.
 See also the manual entry on why $foo[bar] is wrong (unless you first
 define() bar as a constant). If you simply want to check if a constant
 is
 set, use the defined() function.

 So, I think you're relying upon a little work that PHP does for you in
 that
 an undefined CONSTANT is turned into a STRING i.e. bad. Personally,
 I
 *hate* that it does this work, and would love to see a little stricter
 parsing done and throw a fatal error if you try to use an undefined
 constant.

I'm *NOT* relying on that at all.

When it is inside of the quotes or heredoc, it is being parsed by an
entirely different parser with an entirely different grammar, with
absolutely ZERO context the same.

I'm all for making un-quoted unknown literals an E_ERROR instead of
E_NOTICE if you can convince the Internals that the
backwards-compatability break is good...

But don't make me add a bunch of junk to the embedded variable inside
quotes and heredoc!

PHP already knows that these cannot be function names, nor contants,
nor anything other than variables to be embedded there, because of the
quotes or heredoc delimiters.

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

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



Re: [PHP] Split string

2007-05-02 Thread Stut

Richard Lynch wrote:

On Wed, May 2, 2007 4:55 am, Lester Caine wrote:

Fredrik Thunberg wrote:

Lester Caine skrev:

Can someone with a few more working grey cells prompt me with the
correct command to split a string.

The entered data is names, but I need to split the text up to the
first space or comma into one string, and the rest of the string
into
a second. It's the 'first either space or comma' that eludes me at
the
moment :(

In know it's probably obvious, but it always is when you know the
answer.

$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ?
strpos($myString,  ) : strpos($myString, ,);

$part1 = substr($myString, 0, $pos);
$part2 = substr($myString, $pos);

I'm glad I asked now, that is a lot nicer than trying to get the
preg_split
thing working :)


Hnmmm.  Okay, I'll take a shot at it:

$answer = preg_split('|[, ]|', $myString);
var_dump($answer);


Will give more than 2 parts for strings containing both or multiples.

Now please irradiate your hands.

-Stut

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



Re: [PHP] newbie needs help

2007-05-02 Thread Ben Clapp

Thank you, someone had sent me some code that worked on Friday

Ben

Richard Lynch wrote:

On Mon, April 30, 2007 3:37 pm, Ben Clapp wrote:
  

I am new to PHP programming and need some help. I have an image that i
have show up each May for the month with $mymonth = date(m,
mktime()),
but i want to set up a date range for it to show up. Ex. 4-13 to 5-13
each year. How can I do that? Any help would be great.



$now = time();
//leave the year off for 'annual' calculations:
if (mktime(1, 0, 0, 4, 13) = $time  $time = mktime(1, 0, 0, 5, 13)){
  //do something to show your May image.
}
else{
  //show the usual image, or nothing, or whatever
}

  


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



Re: [PHP] PHP + COM (IE Button COM Server)

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 1:46 pm, Iqbal Naved wrote:
 Anybody has implemented a IE button COM server in PHP ? I have found a
 python implementation for this in pywin32 package. My objective is to
 add a
 button in ie which will on click save the url in the address bar. I am
 attatching the iebutton.py with this mail. Also, this is a link in
 msdn
 instructing add toolbar buttons:

 http://msdn2.microsoft.com/en-us/library/aa753588.aspx

 Any code snippet will be extremely useful.

What you want to do is something that happens on the CLIENT, the browser.

PHP runs on the server.

By the time the user is clicking on your button, there is NO php
involved.

Look into JavaScript or ActiveX or something.

php ain't gonna do what you want.

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

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



Re: [PHP] Re: About resource of popen

2007-05-02 Thread Richard Lynch
What's in sig_handler function body, as it relates to $fh and/or
exiting the script?...

I probably won't know the answer, but I'm pretty sure nobody else will
either without that info.

On Wed, May 2, 2007 9:43 am, Fernando chucre wrote:
 Somebody? help me!!

 :D

 2007/4/30, Fernando chucre [EMAIL PROTECTED]:

 Hello all,

 I make a script for read and interprete the stdout of cmd `ip
 monitor`.
 And I use signal_handler, the script is like this:
 ?
 declare(ticks = 1);
 pcntl_signal(SIGHUP,sig_handler,false);


 $fh = popen('ip monitor','r');

 while (!feof($fh))
 {
 $line = fgets($fh);
 analize($line);
 }

 function analize($line) {  ...  } ;
 function sig_handler($signo) { ... };
 ?

 this script run in infine loop, or when to cmd 'ip monitor' exist.
 The
 script ever whait the next line of 'ip monitor', ever. Then when I
 send the
 signal SIGHUP to pid of script. In this point the instruction '$line
 =
 fgets($fh);' is aborted and return false to $line. The $fh is
 modified and
 the function feof($fh) return true and I have not access to $fh
 agaim. But
 the kid process 'ip monitor' is not kill.

 This is wanted?

 --
 Fernando Chure
 PSL/CE




 --
 Fernando Chure
 PSL/CE



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

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



Re: [PHP] Run a script apart from request

2007-05-02 Thread Richard Lynch
On Mon, April 30, 2007 9:55 am, Brad Fuller wrote:
 I am developing a program that does some intensive data processing,
 and is
 triggered from a page hit and/or a SOAP request.

 The processing takes on average 30 seconds to 1 minute, which is OK
 for a
 web page (I can use set_time_limit(0) and just display a
 pseudo-progress bar
 animated gif and a Please wait... message) but I can't leave the
 SOAP
 request hanging for that long.  I need to send a response immediately.

Waiting for 1 minute for a web page is probably not acceptable.

Users won't take it.

Browsers will give up and tell them your page is dead.

And it's just all around a Bad Idea for a web-based application to tie
up HTTP resources that long a time.

And if the SOAP client won't take it anyway, you might as well have
both SOAP and normal users have a cron job list API anyway, since it's
a lot easier to have ONE way to do things instead of two, usually.

 What I really need to do is acknowledge the client that their request
 has
 been received and will be processed, and terminate that request... and
 THEN
 begin the processing.

 One way I thought of doing it would be to put the requests into the
 database
 and run a cron job every X minutes, but I would like to avoid this if
 at all
 possible.

Since that's probably the best way to handle this, why do you want to
avoid it?...

 Someone had suggested pcntl_fork() but I'm not sure if that will
 accomplish
 what I need it to... if I fork(), then send a response, kill the
 parent and
 let the child run the process, will the HTTP request wait for the
 child or
 will it die with the parent (like I want it to) ?

pcntl_fork() in a web environment is a Bad Idea [probably].

[probably explained]
If you have a very heavily tested and controlled web environment,
wherein you have severely pounded on it, with a stable body of code,
and you are 100% sure there are no thread-safety issues, then
pcntl_fork() in a web environment is okay...  The preceding sentence
only applies to about 0.0001% of all web-servers on the planet, at
best. :-v
[/probably]

If you throw pcntl_fork into your average web environment, expect
random crashes, with increasing frequency as load increases.  Sort of
like running Windows, only not. :-)

So pcntl_fork is probably the WORST suggestion, and the MOST
resource-intensive in terms of testing and development, which is
probably your most limited resource, actually.

Doing a fork in the CLI to process the cron jobs in parallel *might*
be a Good Idea if you have a farm of servers or multiple CPUs...  Or
it might just create more overhead with no gain at all, if the
bottleneck is the actual processing and it's not CPU bound to start
with...

You're going to need callgrind to do the job right in the end,
probably... :-)

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

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



Re: [PHP] Split string

2007-05-02 Thread Jim Lucas

Stut wrote:

Richard Lynch wrote:

On Wed, May 2, 2007 4:55 am, Lester Caine wrote:

Fredrik Thunberg wrote:

Lester Caine skrev:

Can someone with a few more working grey cells prompt me with the
correct command to split a string.

The entered data is names, but I need to split the text up to the
first space or comma into one string, and the rest of the string
into
a second. It's the 'first either space or comma' that eludes me at
the
moment :(

In know it's probably obvious, but it always is when you know the
answer.

$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ?
strpos($myString,  ) : strpos($myString, ,);

$part1 = substr($myString, 0, $pos);
$part2 = substr($myString, $pos);

I'm glad I asked now, that is a lot nicer than trying to get the
preg_split
thing working :)


Hnmmm.  Okay, I'll take a shot at it:

$answer = preg_split('|[, ]|', $myString);
var_dump($answer);


Will give more than 2 parts for strings containing both or multiples.

Now please irradiate your hands.

-Stut


This should work for you.
?php
$myString = Here is my first, attempt!;
$answer = preg_split('|[, ]|', $myString, 2);
var_dump($answer);
?

--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

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



Re: [PHP] PHP MySQL - Field Title

2007-05-02 Thread Richard Lynch


On Mon, April 30, 2007 12:47 am, Christian Haensel wrote:
 Good Morning guys and girls

 As I am rather lazy, I don't wanna do a data readout on my MySQL table
 in
 the following way with mysql_fetch_assoc()

 $data_item1=$data['xitem1'];
 $data_item2=$data['yitem2];
 

 I am trying to do the following:

 I have the correct number of fields in the table, which is 116. Now I
 want
 to use a for-loop and read teh data into a string, then shove it into
 another table, which has the exact same layout. I was thinking about
 something like

 for($i=0; $i= 115; $i++) {
 $data_item[$i]=$data[$i];
 }

 but now I have the problem with the field names and all... can someone
 point
 me into the right direction? All I have to so is move the contents of
 one
 field to the second database wich has the same layout as the first DB.

 Would be thankful for any help :o)

If it's MySQL you can bypass PHP altogether and get this done in about
1 second with something like:

SELECT INTO db2.whatever_table FROM db1.whatever_table;

This will essentially just copy the whole dang table.

Feel free to add field names in the syntax from:
http://dev.mysql.com
to change around the order of the fields or even combine/split fields
in simple MySQL functions.
Which you don't need for this task as you described, but somebody else
might.

Also feel free to add a WHERE clause to get only portions of the
table, which again you don't need, but somebody might.

So, really, using PHP for this is probably silly...

That said, you can use mysql_fetch_assoc and get the field names and
use array_keys and array_values to get the field names and values, if
you really really really need PHP to do something in between one db
and the next.

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

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



RE: [PHP] MySQL change-tracking

2007-05-02 Thread Brad Fuller
Richard Lynch wrote:
 I have this simple database and I'm going to have a handful
 of people editing it...
 
 I'd like to track each and every edit with username, and,
 ideally, provide myself an easy Undo if I decide [bleep] is
 an idiot and shouldn't have done that.
 
 Now, I'm not real concerned about the relational foreign key
 aspect here, and I'd like to keep this as simple as possible...
 
 I've considered doing a dump and putting the output into subversion,
 even... 
 
 I realize there may be some nifty MySQL tool that does this,
 so I'll be researching that shortly, but I'm wondering if
 there's a nifty change-management php package out there that
 I should check out.
 
 The users are currently slated to be logging in via HTTP
 Basic Authentication, but I could change that, I guess.
 
 K.I.S.S. is definitely the motto around here -- If it takes
 more than a day or two to figure out, install, and implement;
 then forget it, as I can just hack something together myself in that
 time-frame. 
 
 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some indie artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

I'm not aware of any existing package that offers this, and if there isn't
one I wouldn't be surprised.  I think that there are just too many variables
for it to be universal enough...

But, I thought about it for a second and here's what I came up with...

I realize this is not a very efficient way to store data, but it's just an
idea...

What about instead of running UPDATE queries, you INSERT a new record on
top of it, and if you need to undo someone's change, just DELETE that
record.

I'm not sure how the tables would relate, but it would be something like...
initial insert generates customerID - customerID and customer data go into
a separate table - subsequent changes get stacked up in this table and the
most recent record gets displayed when you click to view the customer.
Voila, you have a history table and a simple way to undo changes.

Whaddya think?

-B

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



Re: [PHP] Changing Session Timeout

2007-05-02 Thread Richard Lynch
On Sun, April 29, 2007 11:50 pm, Aaron Axelsen wrote:
 I did some more investigating, and tracked down the problem.
 Apparently, even though i was setting a separate save_path inside the
 default save path the garbage collector was still picking up the
 sessions in that directory.

 I moved the session save_path dir to a separate location and the
 sessions were removed according to the ini settings.  The 1 weird
 thing
 I noticed is that the session cookie on the client PC is not getting
 set
 properly.  I am trying to set a session timeout of 3 hours, the server
 is set to GMT time, and the client PC is set to CST time.  The cookie
 on
 the client PC reports that it has an expiration time of 1.5 hours
 instead of 3.  Does anyone have any ideas why thats happening?

I'll say it again:

If the client and the server don't agree on what time it is now,
then the client will not return the cookies because they are expired.

If it REALLY matters to you how long a cookie lasts you are better
off having a session cookie, or a 2-year cookie (the max), and
micro-managing the timing out of a session in your PHP code.

I once wasted the better part of a week tracking down a session buglet
because my client's web server clock as OFF by 10 *minutes* from
reality...  Apparently they never heard of NTP over at Microsoft...

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

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



Re: [PHP] Delete first line of a csv file if it is the headers

2007-05-02 Thread Richard Lynch
Do one, and only one, fgetcsv() before you entere the loop?

Or, if only SOME people add the header lines to their CSV file, check
if one of the numeric fields is actually numeric, and skip any bad
lines.

You could even keep a counter going of which line you are on, and give
an error message if you skip any line other than the first line.

It's good to have a counter anyway, as any error message you want to
dump out for an invalid input (and you WILL get them) ought to at
least narrow it down to line and column, so somebody can actually
figure out what's wrong, eh?

On Sun, April 29, 2007 11:06 pm, Richard Kurth wrote:
  The below script will parse a csv file to a database I need to
 remove
 the first line because it is the header files and I don't need them.
 How can
 I test for that and remove them.

  $file = fopen($_POST['copy'], 'r') or $message .= Could not open .
 $_POST[copy] . for reading.BR\n;
 while (!feof($file)){
 # We could easily be importing 10,000 records.
 Give us
 some time here, okay?
 set_time_limit(30);
 $fields = fgetcsv($file, 100);

 if ($fields  count($fields)){
 $recordcount++;

 # Wipe out every possible field, in case they
 have
 some missing:
 reset($possiblefields);
 while (list(,$fieldname) =
 each($possiblefields)){
 $$fieldname = '';
 }

 reset($_POST['fieldorder']);
 $fieldcount = 0;
 $notes = '';
 while (list(,$field) = each($fields)){
 $fieldname =
 $_POST['fieldorder'][$fieldcount++];
 if ($fieldname == 'notes'){
 $notes .= addslashes($field\n);
 }
 elseif ($fieldname == '-- ignore --'){
 # ignore it
 }
 else{
 # Note that file data is not
 Magic-Quoted:
 $$fieldname = addslashes($field);
 }
 }
   require 'importinsert.php';
 }



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

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



Re: [PHP] FW: I really need help

2007-05-02 Thread Richard Lynch
On Sun, April 29, 2007 6:29 pm, Stephen Hernandez wrote:
 These were the values I had to change which I guess is where the
 problem
 is. I was supposed to change host to the name of the computer where
 MySQL is installed. But I do not know what name I should put, the name
 of my site is spanishbyproz.com. In the example Janet uses she puts
 datebasehost.mycompany.com . What should I write for host ?

 I would really appreciate any advice and am sorry it is such a basic
 question.

Only your webhost knows for 100% sure what those should be...

It's often in their FAQ on their site.

Sometimes it's buried in your Control Panel (ugh) on your webserver.

Sometimes it's in your Welcome! email that you got from them.

Sometimes, they expect you to just know that the $host is
'localhost' (which means MySQL runs on the same box as your webserver)
and that the username and password are the same as your login/FTP
username/password for the site itself.

Hope that helps...

If not, you'll have to contact your webhost that you are paying to
host your site, as they are the only ones who really really really
know for sure.

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

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



Re: [PHP] uploads

2007-05-02 Thread Richard Lynch
On Sun, April 29, 2007 4:35 pm, jekillen wrote:
 can someone point me to a system for cleaning
 uploaded files; embedded php scripts in image
 files, viruses etc, shell escape chars, anything
 that would be hazardous?
 The idea is when a file is uploaded, as soon
 as it gets to the server it is inspected, cleaned/rejected
 before it is used or sent anywhere else on the server.
 I am using php to upload anything that would be sent
 in an e-mail attachment. Once the files have been
 'sanitized' they would be made available for display.

What you are asking for is a blacklist of all known viruses...

At that point, you'd want to run something huge like clam-av and/or
spamassassin and/or a generic anti-virus software.

For *most* PHP web applications, what you REALLY want is a very very
very limited allowed set of whitelist of kinds of files to upload --
like only images and PDFs.

If that's what you actually want, it's better to try to check that the
uploaded files *ARE* images or PDFs, than it is to try to rule out
every possible virus ever invented...

I.e., a security whitelist approach is almost always better than a
blacklist approach.

Of course, if you are writing a generic email client type application,
then, yes, you have to go with a generic anti-virus tool like clam-av
or whatever.

It almost-for-sure won't actually be in PHP, and you'll probably have
to use http://php.net/exec, and you may even need to re-think the
general architecture so that the inbound email gets put into some kind
of normal mail queue, and then scrubbed, and then passed into some
kind of normal IMAP mailbox, and then PHP reads the IMAP mailbox, with
PHP taking a hands off approach to the actual scrubbing.

At least, that's the way *I* would do it.  Errr, am doing it.

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

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



Re: [PHP] small picture into thumbnail

2007-05-02 Thread Richard Lynch
On Sun, April 29, 2007 11:15 am, Alain Roger wrote:
 I would like to know how i can display small sized picture in my web
 application ?
 I mean in my database, picture can have max. 500 Kb, however as on 1
 PHP
 page i will display 20 pictures at once, i do not want to force end
 users to
 download all 20 pictures (10Mb around) to have an overview.

 I would like directly on server to resize picture to display them to
 end
 user in format 100px*120px (for example) and like that size should be
 around
 20 or 50Kb per picture.
 I was thinking to use imagecopyresized function for that, but will it
 no
 kill the server CPU and RAM ?

Depends how much traffic you get...

You could write a caching system so that oft-used images have their
thumbnails stored in static files.

Or you could cram the thumbnail into the DB in another field, and only
imagecopyresize it ONCE.

Or both.

If you're already cramming a 500K image into your DB, what's another
20K? :-)

Insert obligatory don't store images in DB flame-war here.

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

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



Re: [PHP] PHP 6: Mysql with iso-8859-1 chars outputting utf-8: Could not convert binary string to Unicode string

2007-05-02 Thread Richard Lynch
This is a question from a guy who does NOT really do Unicode very well...

If everything else in your entire system is iso-8859-1 (aka Latin1)
why are you making your output be utf-8?

Seems to me that that is where the conversion is probably taking place...

On Sun, April 29, 2007 11:07 am, Rangel Reale wrote:
 Hello!

 I have a MySQL database where all tables are in the latin1 character
 set, with accented (Portuguese) characters.

 In my php.ini I have

 
 ; Unicode settings ;
 

 unicode.semantics = on
 unicode.runtime_encoding = iso-8859-1
 unicode.script_encoding = iso-8859-1
 unicode.output_encoding = utf-8
 unicode.from_error_mode = U_INVALID_SUBSTITUTE
 unicode.from_error_subst_char = 3f
 unicode.fallback_encoding = iso-8859-1

 because all my files and data in mysql server are in iso-8859-1.


 When connecting to mysql I issue:

   mysql_query('set names latin1', $this-mysql_link);

 but when I do query in any record that have accented characters I get
 this warning (using mysql_fetch_assoc):

 --
 Could not convert binary string to Unicode string (converter UTF-8
 failed on bytes (0xE7) at offset 9)
 --

 for all accented characters in all fields.


 If I changed the set names query to:

   mysql_query('set names utf8', $this-mysql_link);

 it works, but I would like to keep compatibility with PHP 5, and for
 my application it requires set names to be latin1. Also, my databases
 are not created with the utf8 option.

 As I understood PHP 6's unicode support, all string characters
 (including mysql result values) are converted from
 unicode.runtime_encoding to unicode (utf-16), but looks like it is
 trying to convert from ASCII, which does not have all the accented
 characters. Am I assuming right? How to make mysql_fetch_assoc assume
 field values are in iso-8859-1 instead of ASCII?

 Thanks,
 Rangel Reale



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

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



Re: [PHP] Running processes in windows

2007-05-02 Thread Richard Lynch
On Sun, April 29, 2007 7:54 am, Nathan Wallis wrote:
 I have an application in windows that I am running with a PHP page
 using
 exec  (start..

 I am wondering as to the efficiency of such a statement and how taxing
 it is
 on the server.  If multiple people access a page with such a
 statement, what
 toll does it take on the server and is there a better way to manage
 calls to
 the server side executable?  When this statement is called a command
 prompt
 window appears for the duration of the execution.  I am guessing it
 would be
 possible to crash the server if thousands of these processes we
 created at
 around the same timejust anyone experience would be greatly
 appreciated.

I dunno for sure, but it will probably crash long before you get
thousands of those suckers going at once...

Use ab (errr, that's an Apache benchmark tester) and find out.

Windows guys seem to like something called supersmack or somesuch over
ab, but whatever.

You can get the DOS window to not appear *somehow* but I forget what
it is...




 Thanks.



 Nathan








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

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



Re: [PHP] Split string

2007-05-02 Thread Edward Vermillion


On May 2, 2007, at 4:10 PM, Stut wrote:


Richard Lynch wrote:

On Wed, May 2, 2007 4:55 am, Lester Caine wrote:

Fredrik Thunberg wrote:

Lester Caine skrev:

Can someone with a few more working grey cells prompt me with the
correct command to split a string.

The entered data is names, but I need to split the text up to the
first space or comma into one string, and the rest of the string
into
a second. It's the 'first either space or comma' that eludes me at
the
moment :(

In know it's probably obvious, but it always is when you know the
answer.

$myString = John Doe;

$pos = strpos($myString,  )  strpos($myString, ,) ?
strpos($myString,  ) : strpos($myString, ,);

$part1 = substr($myString, 0, $pos);
$part2 = substr($myString, $pos);

I'm glad I asked now, that is a lot nicer than trying to get the
preg_split
thing working :)

Hnmmm.  Okay, I'll take a shot at it:
$answer = preg_split('|[, ]|', $myString);
var_dump($answer);


Will give more than 2 parts for strings containing both or multiples.

Now please irradiate your hands.



This won't: $answer = preg_split('/(?:,|\s)+/', $myString);

At least not in my tests.

Ed

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



Re: [PHP] problem with shared object file

2007-05-02 Thread Richard Lynch
On Sat, April 28, 2007 6:15 pm, Tijnema ! wrote:
 You have exactly the same problem as i have. My shared hosting has
 safe_mode off en dl on, so i could load them :)
 But i don't have access to write to the php.ini file.
 Maybe we should create such workaround as you provided? Some script
 that uses PHP CLI to load dynamic objects. That would be useful for
 people that use shared hosting, like you and me :)

If you have PHP CLI (or CGI) on your server in the first place, it
already has a flag to let you choose a custom php.ini, so there's
nothing for us to do it's already done

This assumes your webhost didn't get rid of 'exec' and friends, and
has a proper CLI or CGI installed that you can execute as the php
user...

A lot of variables, there, in terms of what a host will and won't allow.

If you can't do what you want with your host, switch hosts. :-)

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

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



RE: [PHP] Script feedback: insert string into another string

2007-05-02 Thread Richard Lynch


On Sat, April 28, 2007 5:10 pm, Brad Sumrall wrote:
 But!
 I am now noticing that the main page provides cookies called
 _utma
 _utmb
 _utmc
 _utmz

 Hmmm

Actually, they each have an extra underscore on front, I think.

__utma etc.

These are from some non-PHP session/cookie management setup, I believe.

Google analytics will cause that, as you are hitting Google's tracking.

Likewise many other popular plug-in HTML/JavaScript stuff like
banner advertisements, inktome, akami, etc.

I'm not quite sure which goofy system needs FOUR friggin' cookies with
a, b, c, and z after __utm, but it's sure annoying as hell to those of
use who don't accept cookies willy-nilly...

I pretty much stop visiting any site that needs to set more than 1
cookie, as I assume its developers haven't got a clue what they are
doing, and therefore I don't want to give them any personal
information, as I don't trust them.

I let the __utma crowd slide, as I know it's some big-time
everybody-use-it mess, but I'm still less likely to give any
substantive input to such a site.

Call me paranoid.

PS Still haven't figured out why you want to report me to PayPal as a
fraud when I don't sell anything through PayPal... :-v

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

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



Re: [PHP] Script feedback: insert string into another string

2007-05-02 Thread Richard Lynch
On Sat, April 28, 2007 5:31 pm, Micky Hulse wrote:
 Brad Sumrall wrote:
 But!
 I am now noticing that the main page provides cookies called
 _utma
 _utmb
 _utmc
 _utmz

 Hmmm

 Wha? Never thought of that.

 It looks like wordwrap() may not be what I am looking for (though,
 still
 researching)... Either way, I am curious to hear what you would do to
 make this script more secure?

 Allowing cookies sounds like a security hole... Any suggestions for
 beefing-up my security would be spectacular! :)

I can GUARANTEE that PHP's wordwrap did NOT issue those cookies.
:-)

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

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



Re: [PHP] problem with shared object file

2007-05-02 Thread Tijnema !

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

On Sat, April 28, 2007 6:15 pm, Tijnema ! wrote:
 You have exactly the same problem as i have. My shared hosting has
 safe_mode off en dl on, so i could load them :)
 But i don't have access to write to the php.ini file.
 Maybe we should create such workaround as you provided? Some script
 that uses PHP CLI to load dynamic objects. That would be useful for
 people that use shared hosting, like you and me :)

If you have PHP CLI (or CGI) on your server in the first place, it
already has a flag to let you choose a custom php.ini, so there's
nothing for us to do it's already done

This assumes your webhost didn't get rid of 'exec' and friends, and
has a proper CLI or CGI installed that you can execute as the php
user...

A lot of variables, there, in terms of what a host will and won't allow.

If you can't do what you want with your host, switch hosts. :-)



Yes, then you should go for www.dapx.com, it has nearly no security :)

Tijnema

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



RE: [PHP] phpbb / sessionid nightmare

2007-05-02 Thread Richard Lynch
On Sat, April 28, 2007 4:46 pm, Brad Sumrall wrote:
 The cookie it's self says
 PHPSESSID=26b7974a5d71c7d0bfebbf71750dac7b
 Path=/
 Host=www.domain.com

 When I go to the jacked up page, I pickup this one
 PHPSESSID=a787e077dd18ed18cb824f664d38315d
 Path=/
 Host=domain.com

As I recall, it depends on your browser settings, maybe, but having
www.domain.com and domain.com will probably break at least *SOME*
browsers/users with strict security settings.

Get your cookies to agree on the domain, and get the URLs to always be
the same as well.

This is usually achieved with DNS settings and Apache in one place,
rather than dinking around in PHP with re-directs, but if all you have
is a hammer...

 In the directory structure, I have gone from
 /phpbb/login.php
 to
 /contest_stories.php?cid=8

 Is the Path or the fact that I am going to www.domain.com to
 domain.com have
 anything to do with it?

The path of / matches both those URLs, and *any* URL for that
matter, so that's fine.

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

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



RE: [PHP] MySQL change-tracking

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 4:32 pm, Brad Fuller wrote:
 Richard Lynch wrote:
 I have this simple database and I'm going to have a handful
 of people editing it...

 I'd like to track each and every edit with username, and,
 ideally, provide myself an easy Undo if I decide [bleep] is
 an idiot and shouldn't have done that.

 Now, I'm not real concerned about the relational foreign key
 aspect here, and I'd like to keep this as simple as possible...

 I've considered doing a dump and putting the output into subversion,
 even...

 I realize there may be some nifty MySQL tool that does this,
 so I'll be researching that shortly, but I'm wondering if
 there's a nifty change-management php package out there that
 I should check out.

 The users are currently slated to be logging in via HTTP
 Basic Authentication, but I could change that, I guess.

 K.I.S.S. is definitely the motto around here -- If it takes
 more than a day or two to figure out, install, and implement;
 then forget it, as I can just hack something together myself in that
 time-frame.

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

 I'm not aware of any existing package that offers this, and if there
 isn't
 one I wouldn't be surprised.  I think that there are just too many
 variables
 for it to be universal enough...

 But, I thought about it for a second and here's what I came up with...

 I realize this is not a very efficient way to store data, but it's
 just an
 idea...

 What about instead of running UPDATE queries, you INSERT a new record
 on
 top of it, and if you need to undo someone's change, just DELETE
 that
 record.

 I'm not sure how the tables would relate, but it would be something
 like...
 initial insert generates customerID - customerID and customer data go
 into
 a separate table - subsequent changes get stacked up in this table
 and the
 most recent record gets displayed when you click to view the customer.
 Voila, you have a history table and a simple way to undo changes.

 Whaddya think?

I worked on a HIPPA-compliant medicasl system like that once (HIPPA
basically don't let you ever ever ever delete any data about a
patient).

It had a version field that got incremented on each insert and you
never did an update or delete.

It annoyed the bleep out of me at the time, mainly because the tables
got really large really fast...

I'll have to think about this and see if the tables I care about will
grow ridiculously large, and I can always archive the older stuff
after time...

Thanks!

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

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



Re: [PHP] Split string

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 4:10 pm, Stut wrote:
 Richard Lynch wrote:
 On Wed, May 2, 2007 4:55 am, Lester Caine wrote:
 Fredrik Thunberg wrote:
 Lester Caine skrev:
 Can someone with a few more working grey cells prompt me with the
 correct command to split a string.

 The entered data is names, but I need to split the text up to the
 first space or comma into one string, and the rest of the string
 into
 a second. It's the 'first either space or comma' that eludes me
 at
 the
 moment :(

 In know it's probably obvious, but it always is when you know the
 answer.
 $myString = John Doe;

 $pos = strpos($myString,  )  strpos($myString, ,) ?
 strpos($myString,  ) : strpos($myString, ,);

 $part1 = substr($myString, 0, $pos);
 $part2 = substr($myString, $pos);
 I'm glad I asked now, that is a lot nicer than trying to get the
 preg_split
 thing working :)

 Hnmmm.  Okay, I'll take a shot at it:

 $answer = preg_split('|[, ]|', $myString);
 var_dump($answer);

 Will give more than 2 parts for strings containing both or multiples.

Yeah, I definitely missed the limit 2 requirement when I read through
the OP.

Though I don't think the 2 bit was the tricky part of the PREG... :-)

 Now please irradiate your hands.

I think they had that done to them way back when, and that's why I
post so much...  You want me to do it again?

:-)

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

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



Re: [PHP] Object-oriented $_REQUEST?

2007-05-02 Thread Richard Lynch


On Sat, April 28, 2007 3:54 pm, js wrote:
 For me, PHP's issetting or emptying $_GET, $_POST or $_REQUEST is
 cumbersome.
 want it to be more easy and comfortable.

 I could say I want a JSP's HttpServletRequest for PHP.
 (http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html)

 I think you're 100% right that it would become slow
 but using this one is a 'option', not mandatory.
 so i think that's not a matter.

I think that it's a particularly daft thing to do as well, but...

class HttpServelentRequest {
  function get ($key) { return $_REQUEST[$key] };
}

Whew. that was tough...

:-)

Yeah, okay, so I ignored the 'method' bit.

That should take you at most another hour to implement.

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

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



Re: [PHP] PHP 6: Mysql with iso-8859-1 chars outputting utf-8: Could not convert binary string to Unicode string

2007-05-02 Thread Rangel Reale

You are right, I really don't know Unicode very much! :P

What I was trying to understand was, because unicode.runtime_encoding =
iso-8859-1, I tought that all internal operations were done in this
encoding, and only when outputting (unicode.output_encoding = utf-8) data
would be converted to utf-8. So to me, I did a mysql query with latin1, data
comes to my variables as iso-8859-1, I use them, and only when I echo'ed
them, they would become utf-8, from a iso-8859-1-to-utf-8-like function.

The strange thing to me, is the mysql_fetch_assoc function give this error
even before I accessed the field values, as I understanded from the above
explanation.

Did I understood it wrong?

Thanks,
Rangel

- Original Message - 
From: Richard Lynch [EMAIL PROTECTED]

To: Rangel Reale [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Wednesday, May 02, 2007 6:53 PM
Subject: Re: [PHP] PHP 6: Mysql with iso-8859-1 chars outputting utf-8:
Could not convert binary string to Unicode string



This is a question from a guy who does NOT really do Unicode very well...

If everything else in your entire system is iso-8859-1 (aka Latin1)
why are you making your output be utf-8?

Seems to me that that is where the conversion is probably taking place...

On Sun, April 29, 2007 11:07 am, Rangel Reale wrote:

Hello!

I have a MySQL database where all tables are in the latin1 character
set, with accented (Portuguese) characters.

In my php.ini I have


; Unicode settings ;


unicode.semantics = on
unicode.runtime_encoding = iso-8859-1
unicode.script_encoding = iso-8859-1
unicode.output_encoding = utf-8
unicode.from_error_mode = U_INVALID_SUBSTITUTE
unicode.from_error_subst_char = 3f
unicode.fallback_encoding = iso-8859-1

because all my files and data in mysql server are in iso-8859-1.


When connecting to mysql I issue:

  mysql_query('set names latin1', $this-mysql_link);

but when I do query in any record that have accented characters I get
this warning (using mysql_fetch_assoc):

--
Could not convert binary string to Unicode string (converter UTF-8
failed on bytes (0xE7) at offset 9)
--

for all accented characters in all fields.


If I changed the set names query to:

  mysql_query('set names utf8', $this-mysql_link);

it works, but I would like to keep compatibility with PHP 5, and for
my application it requires set names to be latin1. Also, my databases
are not created with the utf8 option.

As I understood PHP 6's unicode support, all string characters
(including mysql result values) are converted from
unicode.runtime_encoding to unicode (utf-16), but looks like it is
trying to convert from ASCII, which does not have all the accented
characters. Am I assuming right? How to make mysql_fetch_assoc assume
field values are in iso-8859-1 instead of ASCII?

Thanks,
Rangel Reale




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




--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.463 / Virus Database: 269.6.1/776 - Release Date: 25/4/2007
12:19




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



RE: [PHP] phpbb / sessionid nightmare

2007-05-02 Thread Richard Lynch


On Sun, April 29, 2007 11:28 pm, Brad Sumrall wrote:
 Wait, you might be on to something!
 Phpbb is set to ./domain

That's just plain wrong...

There should be no '/' in there at all...

Shows us the exact line of code from phpbb that does this.

And show us the line[s] of code where you set your cookie parameters.

And, actually, if they don't match up in terms of domain and path,
then don't show us, and do whatever it takes to make them match,
because that's your real problem. :-)

 But, on the page I find nothing related to domain
 This is a new page.
 Think about it as a blank .php page first.

 Now, where would you point me now?

 Brad

 -Original Message-
 From: Chris [mailto:[EMAIL PROTECTED]
 Sent: Monday, April 30, 2007 12:18 AM
 To: Brad Sumrall
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] phpbb / sessionid nightmare

 Brad Sumrall wrote:
 The cookie domain in phpbb is already set at ./domain.com

 I doubt it's set to ./domain.com

 What about your session (ie NOT phpbb) ?

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

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

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




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

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



RE: [PHP] phpbb / sessionid nightmare

2007-05-02 Thread Richard Lynch
On Sat, April 28, 2007 5:51 pm, Brad Sumrall wrote:
 I understand where you are going with the mysql injection.
 It would appear as though the entire session is being dictated by this
 _utmX
 session which I have never seen before.

 It would appear as though the /index.php sets this java bases session
 variable and since phpbb does not use this, it never even tries to set
 or
 look at the java session.

 I guess the key question here is;

 1 What is the _utmX session, I find little on google, other than it
 uses it?

It's used by Google, and only by Google, and PHP is not even paying
attention to those cookies at all, in any way, shape, or form, other
than having them clutter up $_COOKIE, maybe.

 2 How to teach phpbb to use it?

Don't.

If you don't want the __utma stuff confusing you, take out your Google
analytics and Google adsense junk until you have debugged your PHP.

Then put the Google stuff back in, and it will not have any effect.

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

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



Re: [PHP] problem with shared object file

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 5:10 pm, Tijnema ! wrote:
 On 5/3/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Sat, April 28, 2007 6:15 pm, Tijnema ! wrote:
  You have exactly the same problem as i have. My shared hosting has
  safe_mode off en dl on, so i could load them :)
  But i don't have access to write to the php.ini file.
  Maybe we should create such workaround as you provided? Some
 script
  that uses PHP CLI to load dynamic objects. That would be useful
 for
  people that use shared hosting, like you and me :)

 If you have PHP CLI (or CGI) on your server in the first place, it
 already has a flag to let you choose a custom php.ini, so there's
 nothing for us to do it's already done

 This assumes your webhost didn't get rid of 'exec' and friends, and
 has a proper CLI or CGI installed that you can execute as the php
 user...

 A lot of variables, there, in terms of what a host will and won't
 allow.

 If you can't do what you want with your host, switch hosts. :-)


 Yes, then you should go for www.dapx.com, it has nearly no security :)

Hopefully that is exactly what their clients need. :-v

I know some experts think my webhost is daft to let me do a 'dl' and
pull in whatever .so file I want to an Apache 1.x mod_php setup...
[shrug]

I figure if the person buying the webhosting and the person selling
the webhosting are both happy, and if neither is doing something
egregious to the rest of us (e.g., spam) then let them work it out
between themselves, eh?

There are enough hosts around with enough different ways of doing
things that you just have to try several of them until you find an
environment you like.

Or, in my case, 3 different environments for differing needs of
diverse projects, actually...

I've never understood why somebody would stick around with a host that
is clearly not suited to their needs, though...

I guess your first move can be so traumatic that you never realize
that it's not that big a deal with a little prep and planning, so you
stick with your second host no matter what...

But I had several forced moves early on, and enough different clients
with hosts I hated, that I figured out what I wanted and went and
found it over the years...

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

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



Re: [PHP] Bounce composition

2007-05-02 Thread Richard Lynch


On Wed, May 2, 2007 2:57 pm, Oliver Block wrote:
 Am Mittwoch, 2. Mai 2007 20:11 schrieb Richard Lynch:
 Does anybody have or know of a good simple PHP script that can take
 an
 email as an input, and compose a Bounce email as output?

 I need something that does just that, without a huge framework or a
 zillion other features...

 please try this:

 $env['from'] = '[EMAIL PROTECTED]';
 $env['to'] = '[EMAIL PROTECTED]';
 $env['remail'] = imap_fetchheader($stream, $msgno);

I don't think that's what a bounce looks like, is it?...

I guess I was hoping somebody had worked out the minutiae of composing
a bounce message in PHP from the input headers.

I don't need help with the IMAP part of it, just the RFC bit about
making up a bounce message, without actually having to spend hours
poring over RFCs, which is not my idea of a Good Time... :-)

Or maybe I'm making a mountain out of a molehill, and that IS what a
bounced email looks like...

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

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



Re: [PHP] PHP 6: Mysql with iso-8859-1 chars outputting utf-8: Could not convert binary string to Unicode string

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 5:32 pm, Rangel Reale wrote:
 You are right, I really don't know Unicode very much! :P

 What I was trying to understand was, because unicode.runtime_encoding
 =
 iso-8859-1, I tought that all internal operations were done in this
 encoding, and only when outputting (unicode.output_encoding = utf-8)
 data
 would be converted to utf-8. So to me, I did a mysql query with
 latin1, data
 comes to my variables as iso-8859-1, I use them, and only when I
 echo'ed
 them, they would become utf-8, from a iso-8859-1-to-utf-8-like
 function.

 The strange thing to me, is the mysql_fetch_assoc function give this
 error
 even before I accessed the field values, as I understanded from the
 above
 explanation.

 Did I understood it wrong?

No, you're probably right...

I think that PHP may be biased toward UTF-16 (32?) internally, and
be converting to/from UTF-16 and keeping everything in UTF-16
internally...

But, really, since PHP 6 is not actually released yet, you probably
need to be asking about this on Internals, I think, to get a real
answer...

I suspect you'll still want to use iso-8859-1 on the output after you
solve this bug, though, if you don't want it converted to utf-8 in the
end..

You may also want to just try it with unicode semantics OFF, since
that's probably the least debugged and biggest change in PHP 6, and if
you do *everything* in Latin1, that's pretty much the state PHP was in
since nineteen-ninety-mumble, and it will just work anyway...

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

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



Re: [PHP] Re: What does mean?

2007-05-02 Thread Edward Vermillion


On May 2, 2007, at 3:59 PM, Richard Lynch wrote:

[snip]




One think you could consider to avoid the ugliness is to put the
heredoc into a one-use function or in an incldue file that doesn't
have enough indenting for it to look ugly in the first place. :-)



That's what I do with 'em, and that's exactly why. Can't stand to  
have things not look right, even if it does cost a function call.


At least until costing a function call matters more than being able  
to change things without going cross-eyed.


Ed

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



Re: [PHP] Script feedback: insert string into another string

2007-05-02 Thread Micky Hulse
Hey Richard! Thanks for the reply. I was hoping someone would re-visit 
my questions.


Richard Lynch wrote:

I can GUARANTEE that PHP's wordwrap did NOT issue those cookies.


Oh, for sure. I understand that.

I guess what I was trying to say/ask was this:

1. wordwrap() is a little different than the function I wrote because it 
counts characters only... I need to count words. I am sure wordwrap 
could be modified to count words, but I have yet to really explore this 
option.


2. Brad S. posted some information about cookies and my script, but did 
not really explain what he was talking about... I just read your post 
about what those cookies are, and it makes things a bit more clear 
(thanks!), but what was Brad getting at? I want good security, and it 
sounded like Brad was saying he could access cookies through my form? I 
am not very familiar with XSS attacks, but that sounded like what Brad 
was getting at... So my first thought was this:


I thought striptags() would take care of such problems [XSS attack]... 
but it sounds like I need to filter my [input] strings [via form] with 
htmlentities... no?


Lol, I hope I am not confusing you or anyone else. :D

Thanks again for you help! I really appreciate it.

Have a great day and/or night.
Cheers!
Micky





--
Wishlists: http://snipurl.com/1gqpj
   Switch: http://browsehappy.com/
 BCC?: http://snipurl.com/w6f8
   My: http://del.icio.us/mhulse

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



Re: [PHP] Script feedback: insert string into another string

2007-05-02 Thread Micky Hulse

Hi Richard! Thanks again for your help on this one. ;)

Richard Lynch wrote:

These are from some non-PHP session/cookie management setup, I believe.


Ahhh, very interesting! Thanks for the clarification. :)


Call me paranoid.


Better that than spammed! :D


PS Still haven't figured out why you want to report me to PayPal as a
fraud when I don't sell anything through PayPal... :-v


Not me. I got your back though!

Have a great day/night,
cheers,
Micky


--
Wishlists: http://snipurl.com/1gqpj
   Switch: http://browsehappy.com/
 BCC?: http://snipurl.com/w6f8
   My: http://del.icio.us/mhulse

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



Re: [PHP] Bounce composition

2007-05-02 Thread Travis Doherty
Richard Lynch wrote:

On Wed, May 2, 2007 2:57 pm, Oliver Block wrote:
  

Am Mittwoch, 2. Mai 2007 20:11 schrieb Richard Lynch:


Does anybody have or know of a good simple PHP script that can take
an
email as an input, and compose a Bounce email as output?

I need something that does just that, without a huge framework or a
zillion other features...
  

please try this:

$env['from'] = '[EMAIL PROTECTED]';
$env['to'] = '[EMAIL PROTECTED]';
$env['remail'] = imap_fetchheader($stream, $msgno);



I don't think that's what a bounce looks like, is it?...

I guess I was hoping somebody had worked out the minutiae of composing
a bounce message in PHP from the input headers.

I don't need help with the IMAP part of it, just the RFC bit about
making up a bounce message, without actually having to spend hours
poring over RFCs, which is not my idea of a Good Time... :-)

Or maybe I'm making a mountain out of a molehill, and that IS what a
bounced email looks like...

  

Hey Richard,

DJB's bounce format is pretty popular:
http://cr.yp.to/proto/qsbmf.txt

Best case would be to give a 400 for temp failure (plz try later) or a
500 for perm error right at the mail server.  Not sure if you can get
your logic in up the stream though before it gets to you.  If you can
you never have to deal with bounce messages and the entire queuing
process that goes along with it, mail server maintenance, etc..

Bounce to the enveloper sender, not the From header.  I also believe
bounces are supposed to have an envelope sender of  to avoid bounce
loops... not sure on that though.

Cheers
Travis Doherty

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



[PHP] A problem with passing $_GET in an url

2007-05-02 Thread Davis Chan
Hi! New to this newsgroup and is debugging a strange behaviour in a site 
under development. The developement platform is a Linux box running 
Fedora Core 6, Apache 2.2.3-5 and php-5.1.6-3. Here is the general flow 
of that particular part of the site:


php generated form ---(data submitted by pressing submit on the form 
and ok on a javascript confirm box)--- 
window.location=./script.php?var=value --- script.php process the 
form data


The problem is I cannot pass the var=value to script.php (the url on 
browser only says ./script.php? and $_GET is empty with a print_r() ) 
but if I type in the url manually, the script.php works. I checked the 
javascript also and it is ok.


I understand this might not be a php problem but I am totally lost. Any 
idea, insight, opinion is welcomed. Thanks.


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



Re: [PHP] PHP's ldap_sasl_bind tries to authenticate with KRB5CCNAME other than the one provided by mod_auth_kerb

2007-05-02 Thread gil ran

On 5/2/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 2, 2007 9:41 am, gil ran wrote:
 I am using Apache-2.2.2 with mod_auth_kerb-5.3, php-5.2.1,
 openldap-2.3.27 cyrus-sasl-2.1.21 and heindal-0.7.2 on a
 Linux-from-scratch based system.

 The problem I'm presenting is probably a PHP issue or an Apache issue,
 or a mod_auth_kerb issue. I could not understand which one causes the
 problem.

 I am trying to connect using SASL and GSSAPI to the LDAP server from a
 PHP script that runs on the Apache server.

 The script (in short) does the following:
   putenv(KRB5CCNAME= . $_SERVER['KRB5CCNAME']);
   echo getenv(KRB5CCNAME);
   system(klist);

Always use 'exec' instead, and ALWAYS get the output and the error
code and ALWAYS ALWAYS ALWAYS check the error code!


This is not the full code. I did check error codes. Lets call this a
summery of the code.
The system command is meant to check if the KRB5CCNAME environment
variable is the valid one when used with system. This proved that
the variable was indeed passed in this case.


   $ldapconn = ldap_connect(ldap://example.org;) || die(...);
   ldap_sasl_bind($ldapconn, NULL, NULL, GSSAPI) || die(...);

 When I run the script manually from a shell that has a proper
 KRB5CCNAME environment variable, both the system(klist) and the
 ldap_sasl_bind(...) work as they should.

When you run the script manually from a shell, you are probably NOT
the same User as PHP runs as, and you are probably NOT using the same
shell either, and you therefore almost certainly do NOT have the same
environment for your test as for Reality.


This is true. I tried from a shell (meaning, running from bash `php
filename') in order to debug more easily, and found out that it
always works this way.


This is like stunt-driving a car on a Closed Course with a
Professional Driver, and then pretending that it's safe to do that
same stunt on a busy city street... :-)

99.9% of the time, this problem boils down to:
paths and permissions

Use a FULL PATH for any file/program in your exec call:
NOT klist
/usr/bin/klist
/usr/local/bin/klist
/sharedhost/example.com/usr/local/i/compiled/it/myself/bin/klist

NOT somefile.txt
/full/path/to/wherever/it/lives/somefile.txt


But klist worked. As I said, the klist was added for debug purpose only.


 When I run `restart Apache' and then enter to the PHP page for the
 first time both work as well. The KRB5CCNAME written is
 /tmp/krb5ccname_apache_something

I dunno what klist does, nor what any of the KRB stuff is, but if you
want to preserve this KRB thingie from page to page, it looks like you
will need to do more than just run 'klist'...


I don't want to preserve this KRB thingie from page to page. The
opposite is correct: I don't understand why the old file-name is used
instead of the new one.

OK. I'll give some background about KRB5CCNAME, klist, etc.
`klist' is a command that lists the tickets (credentials) that the
current kerberos user holds.
`KRB5CCNAME' contains the full path to a temporary file that holds the
credentials data. This information is passed to the apache by the
browser. The file itself is created by Apache (mod_auth_kerb). Apache
(mod_auth_kerb) also initializes`KRB5CCNAME'.

When using ldap_sasl_bind with the 4th argument set to GSSAPI we are
trying to bind to the ldap server using sasl and GSSAPI. The GSSAPI
ignores any provided username/password (authcid, for those of you who
are familiar with sasl). Instead, it uses the information kept in the
credential cache file. This is the file Apache (mod_auth_kerb)
creates. This is the file-name provided by it in
$_SERVER['KRB5CCNAME'].

When using GSSAPI for authentication it reads the current credentials
from the credential cache file. It knows where it is according to
the environment variable `KRB5CCNAME'.

In this case, for some reason, while KRB5CCNAME contains the correct
value, GSSAPI is not using it. It is using some other value.


You'll need to store the setting somewhere, transmit that storage
location through the stateless HTTP protocol (just like
GET/POST/COOKIE is used) and then retrieve it if it's already been
stored, or make a new one, as appropriate for whatever you are trying
to do, which I also don't really understand, but there it is.


Not relevant. The problem is not that the data is not stored, it's
that the data is stored when I don't want it to be.


 After that, each time I enter the page I get some other KRB5CCNAME
 (other than the one I got before), the system(klist) command works
 as it should, but ldap_sasl_bind returns Local error. In this case I
 also get an error written to /var/log/auth. This error says that the
 file /tmp/krb5ccname_apache_something could not be found (this is
 the same something that was written by PHP after I restarted
 Apache). This means that the authentication process tries to use the
 previous file-name.

See above.

 I added a debug print to PHP's ldap_sasl_bind function that prints
 `getenv(KRB5CCNAME)' to Apache's 

  1   2   >