php-general Digest 21 Jul 2006 18:36:13 -0000 Issue 4251

Topics (messages 239675 through 239689):

Re: headers and newline at end of script
        239675 by: Jochem Maas

UTF-8 With content-type text/xml problem.
        239676 by: Mathijs
        239678 by: Barry
        239679 by: Jon Anderson

Re: PAYMENT TRANSACTION
        239677 by: tedd

Stumped! 4.x to 5.1 problem!!
        239680 by: Mark
        239682 by: Mark

Re: Setting cookie on one domain for an other domain
        239681 by: Mark

Bug in == comparison?
        239683 by: Jeffrey Sambells
        239684 by: Adam Zey
        239685 by: Adam Zey
        239686 by: Adam Zey
        239687 by: Adam Zey
        239688 by: Jeffrey Sambells

Re: Enterprise grade CMS+Ecomm
        239689 by: Chris W. Parker

Administrivia:

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

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

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Robert Cummings wrote:
> On Thu, 2006-07-20 at 16:50, Jochem Maas wrote:
>> Robert Cummings wrote:
>>> On Thu, 2006-07-20 at 14:15, Martin Marques wrote:
>>>> On Thu, 20 Jul 2006 13:06:10 -0400, Robert Cummings <[EMAIL PROTECTED]> 
>>>> wrote:
>>>>> On Thu, 2006-07-20 at 12:12, Adam Zey wrote:
>>>>>> Martin Marques wrote:
>>>>>>   > Now, my question is: Is it a bad practice to "NOT" close the script
>>>>>> with
>>>>>>> the PHP closing "?>"? I mean, just leave the script without a closing
>>>>>>> PHP simbols, as this scripts are included?
>>>>>> Yes.
>>>>> Wrong :)
>>>> Why? ;-)
>>> See links I posted in previous response >:)
>> I don't understand - the links point to posts by Rasmus saying that's
>> 'beneficial' - seems to me to be a fairly robust endorsement yet you
>> consider leaving off trailing '?>' wrong (and use Rasmus' comments to
>> back that up)
>>
>> we're having another heatwave here in europe so that
>> could be compounding my lack of understanding ;-)
> 
> The original question says "Is it bad practice?" Adam Zey said "Yes". I
> said he is "Wrong". Now granted, re-reading the original post, there are
> two questions, I presumed (quite possibly incorrectly) Adam Zey was
> answering the first. Generally when you have Y answers for X questions
> and Y < X then the first Y questions are presumed answered. Just like
> when parsing CSV files and you run out of commas :) If we didn't have
> this basic presumption, then the universe would begin to tear apart --
> trust me on that one ;)

ah, I think Im back on track now :-)

> 
> Cheers,
> Rob.

--- End Message ---
--- Begin Message ---
Hello ppl,

I have a big prob.

I have a page which post some input.
This input can be UTF-8 like chinese or other utf-8 chars.
Also i need it to return UTF-8 and it has to be xml.

For some strange reason this isn't working.

Small example.

PHP Code:
<?php
header('Content-Type: text/xml; charset=utf-8');
print '<?xml version="1.0" encoding="utf-8" ?>'."\n";
print '<test><data>'.$_GET['test'].'</data></test>'."\n";
?>

as GET var fill in something like ?test=éëêæ

This will break it..
Only Opera does a good job. Firefox and IE both can't handle it.
If i remove the header Firefox goes well.
IE Still can't handle it.

I Just need simple XML with UTF8 data.

PS:
This also breaks database saving, it doesn't save correct.
And i have mbstring installed.


Thx in advance.


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0629-1, 07/19/2006
Tested on: 7/21/2006 11:17:03 AM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com

--- End Message ---
--- Begin Message ---
Mathijs schrieb:
Hello ppl,

I have a big prob.

I have a page which post some input.
This input can be UTF-8 like chinese or other utf-8 chars.
Also i need it to return UTF-8 and it has to be xml.

For some strange reason this isn't working.

Small example.

PHP Code:
<?php
header('Content-Type: text/xml; charset=utf-8');
print '<?xml version="1.0" encoding="utf-8" ?>'."\n";
print '<test><data>'.$_GET['test'].'</data></test>'."\n";
?>

as GET var fill in something like ?test=éëêæ

This will break it..
Only Opera does a good job. Firefox and IE both can't handle it.
If i remove the header Firefox goes well.
IE Still can't handle it.

I Just need simple XML with UTF8 data.

PS:
This also breaks database saving, it doesn't save correct.
And i have mbstring installed.


Thx in advance.

Is the output also UTF-8 encoded?

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

--- End Message ---
--- Begin Message ---
I'm somewhat new to this stuff as well, so take this with a grain of salt...

Someone else was hinting at this, but more directly, try running utf8_encode() on whatever part of your data that requires utf8 encoding. In the case of your example, you could just utf8_encode the test get variable. To extend your example a little:

header('Content-Type: text/xml; charset=utf-8');
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
print "<test>\n";
print " <origEncoding>" . mb_detect_encoding($_GET['test']) . "</origEncoding>\n";
print " <utf8data1>" . utf8_encode($_GET['test']) . "</utf8data1>\n";
print " <utf8data2>" . mb_convert_encoding($_GET['test'],'UTF-8') . "</utf8data2>\n";
print "</test>\n";

I tried this with: 會意字/会意字, which I stole from Wikipedia. I don't have a clue what it means.

jon

Mathijs wrote:
Hello ppl,

I have a big prob.

I have a page which post some input.
This input can be UTF-8 like chinese or other utf-8 chars.
Also i need it to return UTF-8 and it has to be xml.

For some strange reason this isn't working.

Small example.

PHP Code:
<?php
header('Content-Type: text/xml; charset=utf-8');
print '<?xml version="1.0" encoding="utf-8" ?>'."\n";
print '<test><data>'.$_GET['test'].'</data></test>'."\n";
?>

as GET var fill in something like ?test=éëêæ

This will break it..
Only Opera does a good job. Firefox and IE both can't handle it.
If i remove the header Firefox goes well.
IE Still can't handle it.

I Just need simple XML with UTF8 data.

PS:
This also breaks database saving, it doesn't save correct.
And i have mbstring installed.


Thx in advance.


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0629-1, 07/19/2006
Tested on: 7/21/2006 11:17:03 AM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com


--- End Message ---
--- Begin Message ---
At 12:37 AM -0700 7/21/06, BBC wrote:
>How are you all?
>I hope some body can give me some references for internet payment.
>I made a kind of shopping cart in my project; even though I was doubt in 
>making it caused I don't have any idea how to make internet
>transaction. But I just heard from a friend of mine that we can 'join' with 
>special web site which handles payment transaction.
>I'll be pleasure if some body can give references about this issue which 
>explains how to collaborate with them step by step.
>Thank you guys..

Try PayPal.

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

--- End Message ---
--- Begin Message ---
I have an extension that seems to create PHP variables correctly, and
var_dump() doesn't seem to have a problem. but upon moving to 5.1.x it
fails.

Anyone have a suggestion?

<xmp> <xmldbx version='1.0'><ycis_host t='a' R='1' C='2' cb='2' ><xag t='o' 
nm='0' cn='classfoo' ><hostname t='sz' v='foo'/></xag><xag t='o' nm='1' 
cn='classfoo' ><hostname t='sz' v='bar'/></xag></ycis_host></xmldbx><xmp><p>
array(2) {
  [0]=>
  object(classfoo)#2 (1) {
    ["hostname"]=>
    string(3) "foo"
  }
  [1]=>
  object(classfoo)#3 (1) {
    ["hostname"]=>
    string(3) "bar"
  }
}
array(2) {
  ["0"]=>
  object(classfoo)#4 (1) {
    ["hostname"]=>
    string(3) "foo"
  }
  ["1"]=>
  object(classfoo)#5 (1) {
    ["hostname"]=>
    string(3) "bar"
  }
}
Object failed

Attachment: foo.php
Description: application/php


--- End Message ---
--- Begin Message ---
Mark wrote:

> I have an extension that seems to create PHP variables correctly, and
> var_dump() doesn't seem to have a problem. but upon moving to 5.1.x it
> fails.
> 
> Anyone have a suggestion?

Well, it is fixed. Evidently, PHP 5.1 sees a difference between $var["0"]
and $var[0]. It never did before.

BTW: this behavior is almost certainly in wddx.

--- End Message ---
--- Begin Message ---
Peter Lauri wrote:

> Best group member,
> 
>  
> 
> When a user does a specific action on domain1.com I want a cookie to be
> set so that domain1.com and domain2.com can reach it. Ok, after reading
> the manual for setcookie() I tried this:
> 
>  
> 
> setcookie("thevariable", "thevalue", time()+60*60*24*30, "/",
> ".domain1.com");
> 
> setcookie("thevariable", "thevalue", time()+60*60*24*30, "/",
> ".domain2.com");
> 
>  
> 
> However, I can not detect the cookie at domain2.com.
> 
>  
> 
> A solution would be to just make a redirect to the other domain where the
> cookie is set and then return.
> 
>  
> 
> Question is: Can I not set a cookie at domain1.com to work at domain2.com?

This is a common problem, and the easiest solution, if you have control over
both domains, is to put a "bug" (a small image) on domain1 and domain2,
something like:

showlogo.php

Which returns a jpeg of an image. The trick is that you send it a parameter
such as:

http://domain2.com/showlogo.php?session=MYSESESSION

Then this code sets its cookie in domain2, so when you go there it is there.


You should try to use encryption, temp variables, or something to keep this
from being easy to hack.

--- End Message ---
--- Begin Message ---

OK I have a very strange bug:

In the middle of my script I have these two lines:

var_dump($test,$test2);
echo "'$test'=='$test2' is ".($test==$test2);

which is giving:

int(0) string(6) "Points"
'0'=='Points' is 1

I understand that PHP is loose typed and automatically does type conversion but in the many years I've been using PHP (mostly v4) the comparison had always converted to 'string' and in the case above returned FALSE, not TRUE. It seems here they are comparing as integers thus 'Points' evaluates to 0 and the comparison is TRUE.

I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality.

Any ideas why this is suddenly happening? I'm using PHP 5.1, and I realize I could use other functions such as strval() in the comparison however I've used similar logic in the past without problems.

Any help would be great.

Thanks

Jeff



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeffrey Sambells
Director of Research and Development
Zend Certified Engineer (ZCE)

We-Create Inc.
[EMAIL PROTECTED] email
519.745.7374 x103 office
519.897.2552 mobile

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get Mozilla Firefox at
http://spreadfirefox.com

--- End Message ---
--- Begin Message ---
Jeffrey Sambells wrote:

OK I have a very strange bug:

In the middle of my script I have these two lines:

var_dump($test,$test2);
echo "'$test'=='$test2' is ".($test==$test2);

which is giving:

int(0) string(6) "Points"
'0'=='Points' is 1

I understand that PHP is loose typed and automatically does type conversion but in the many years I've been using PHP (mostly v4) the comparison had always converted to 'string' and in the case above returned FALSE, not TRUE. It seems here they are comparing as integers thus 'Points' evaluates to 0 and the comparison is TRUE.

I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality.

Any ideas why this is suddenly happening? I'm using PHP 5.1, and I realize I could use other functions such as strval() in the comparison however I've used similar logic in the past without problems.

Any help would be great.

Thanks

Jeff

No, the opposite is true; strings are always converted to integers in such comparisons, as stated in TFM:

http://www.php.net/manual/en/language.operators.comparison.php

I'll quote it here:

"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement."

In your case, it's a bug in your code; you should be using === to also verify type, or casting $var1 to a string in your comparison.

Regards, Adam Zey.

--- End Message ---
--- Begin Message ---

I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality.

Wups, I missed the last part there. You want the empty() function:

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

It can do exactly what you want.

Regards, Adam.

--- End Message ---
--- Begin Message ---
Jeffrey Sambells wrote:
hrm..

It just seemed strange as the script I was working on is 3 years old and had worked flawlessly until today.

Thanks.

- Jeff

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeffrey Sambells
Director of Research and Development
Zend Certified Engineer (ZCE)

We-Create Inc.
[EMAIL PROTECTED] email
519.745.7374 x103 office
519.897.2552 mobile

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get Mozilla Firefox at
http://spreadfirefox.com

On 21-Jul-06, at 12:45 PM, Adam Zey wrote:

Jeffrey Sambells wrote:
OK I have a very strange bug:
In the middle of my script I have these two lines:
var_dump($test,$test2);
echo "'$test'=='$test2' is ".($test==$test2);
which is giving:
int(0) string(6) "Points"
'0'=='Points' is 1
I understand that PHP is loose typed and automatically does type conversion but in the many years I've been using PHP (mostly v4) the comparison had always converted to 'string' and in the case above returned FALSE, not TRUE. It seems here they are comparing as integers thus 'Points' evaluates to 0 and the comparison is TRUE. I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality. Any ideas why this is suddenly happening? I'm using PHP 5.1, and I realize I could use other functions such as strval() in the comparison however I've used similar logic in the past without problems.
Any help would be great.
Thanks
Jeff

No, the opposite is true; strings are always converted to integers in such comparisons, as stated in TFM:

http://www.php.net/manual/en/language.operators.comparison.php

I'll quote it here:

"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement."

In your case, it's a bug in your code; you should be using === to also verify type, or casting $var1 to a string in your comparison.

Regards, Adam Zey.

Since my other reply might have been overlooked as a double-reply, it bears repeating here; the empty() function is designed to do what you want (check empty strings, int(0), null, etc).

Regards, Adam.

--- End Message ---
--- Begin Message ---
Jeffrey Sambells wrote:
hrm..

It just seemed strange as the script I was working on is 3 years old and had worked flawlessly until today.

Thanks.

- Jeff

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeffrey Sambells
Director of Research and Development
Zend Certified Engineer (ZCE)

We-Create Inc.
[EMAIL PROTECTED] email
519.745.7374 x103 office
519.897.2552 mobile

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get Mozilla Firefox at
http://spreadfirefox.com

On 21-Jul-06, at 12:45 PM, Adam Zey wrote:

Jeffrey Sambells wrote:
OK I have a very strange bug:
In the middle of my script I have these two lines:
var_dump($test,$test2);
echo "'$test'=='$test2' is ".($test==$test2);
which is giving:
int(0) string(6) "Points"
'0'=='Points' is 1
I understand that PHP is loose typed and automatically does type conversion but in the many years I've been using PHP (mostly v4) the comparison had always converted to 'string' and in the case above returned FALSE, not TRUE. It seems here they are comparing as integers thus 'Points' evaluates to 0 and the comparison is TRUE. I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality. Any ideas why this is suddenly happening? I'm using PHP 5.1, and I realize I could use other functions such as strval() in the comparison however I've used similar logic in the past without problems.
Any help would be great.
Thanks
Jeff

No, the opposite is true; strings are always converted to integers in such comparisons, as stated in TFM:

http://www.php.net/manual/en/language.operators.comparison.php

I'll quote it here:

"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement."

In your case, it's a bug in your code; you should be using === to also verify type, or casting $var1 to a string in your comparison.

Regards, Adam Zey.

Since my other reply might have been overlooked as a double-reply, it bears repeating here; the empty() function is designed to do what you want (check empty strings, int(0), null, etc).

Regards, Adam.

--- End Message ---
--- Begin Message ---
hrm..

It just seemed strange as the script I was working on is 3 years old and had worked flawlessly until today.

Thanks.

- Jeff

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeffrey Sambells
Director of Research and Development
Zend Certified Engineer (ZCE)

We-Create Inc.
[EMAIL PROTECTED] email
519.745.7374 x103 office
519.897.2552 mobile

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get Mozilla Firefox at
http://spreadfirefox.com

On 21-Jul-06, at 12:45 PM, Adam Zey wrote:

Jeffrey Sambells wrote:
OK I have a very strange bug:
In the middle of my script I have these two lines:
var_dump($test,$test2);
echo "'$test'=='$test2' is ".($test==$test2);
which is giving:
int(0) string(6) "Points"
'0'=='Points' is 1
I understand that PHP is loose typed and automatically does type conversion but in the many years I've been using PHP (mostly v4) the comparison had always converted to 'string' and in the case above returned FALSE, not TRUE. It seems here they are comparing as integers thus 'Points' evaluates to 0 and the comparison is TRUE. I tried comparing in the reverse sequence ($test2==$test) and the same occurred. It does work as expected if I have === but the rest of the scirpt isn't type sensitive so I want NULL, 0, and empty string to still maintain equality. Any ideas why this is suddenly happening? I'm using PHP 5.1, and I realize I could use other functions such as strval() in the comparison however I've used similar logic in the past without problems.
Any help would be great.
Thanks
Jeff

No, the opposite is true; strings are always converted to integers in such comparisons, as stated in TFM:

http://www.php.net/manual/en/language.operators.comparison.php

I'll quote it here:

"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement."

In your case, it's a bug in your code; you should be using === to also verify type, or casting $var1 to a string in your comparison.

Regards, Adam Zey.

--- End Message ---
--- Begin Message ---
Larry Garfield <mailto:[EMAIL PROTECTED]>
    on Thursday, July 20, 2006 6:36 PM said:

> On Thursday 20 July 2006 11:30, Chris W. Parker wrote:
> 
> Drupal has its own ecommerce suite that is reasonably robust all on
> its own.

Yeah I saw that module. I think today I am going to try to set them both
up.


Thanks for your input.
Chris.

--- End Message ---

Reply via email to