For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2008 > problem with php, json, browser, charset









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author problem with php, json, browser, charset
Pugi!

2008-01-05, 7:00 pm

Hi,

I am having a problem that is occuring when using php, json, utf-8
charset and IE7.
It sounds like a browser (thus client side) problem but since it is
occuring on a php driven website, I think the best help I can get is
here.
Given: webpage (valid XHTML, utf-8 charset) with form (I use the YUI
dialog), using javascript I collect all the user input on the form,
store it in an object, json encode it, send it to the server (AJAX
GET, no form submit), json decode it, validate and sanitize it, store
it in database when ok, otherwise create error message and send
response back to the client.
The problem occures when the user inputs coordinates like 53=B016'35''.
which is allowed. It works fine with FF, Safari and Opera, but not
with IE7 (dont' know for IE6). Before the request is send to the
server I visualize the json encoded information and the url with
querystring in an alert and there is no difference here between IE7
and other browsers, but once it arrives on the server there is a
difference:
The first log line is the url + querystring, the second line is the
result of $_GET['data'].
When I use json_decode(stripslashes($data), true) the result is an
associative array for FF, Safari and Opera, but empty for IE7. Where
is the problem ? The charset, the urlencoding, ... ?

FF, Safari, Opera log:
05/01/2008 17:37:45 - 192.168.1.2 - url =3D /webpage.php?
action=3Dmodform& data=3D{%22FormID%22:%2221%22,%22Fieldse
tID
%22:%2287%22,%22XAttrID%22:%2218%22,%22L
abel%22:%22Max.%20longitude
%22,%22Units%22:%22%22,%22ToolTip%22:%22
Maximum%20longitude
%20(-180%20to%20180).%20Valid%20formats
%20:%2053.5,%2053%C2%B016.2,%2053%C2%B016'20.5%20and%2053%C2%B016'22''.
%22,%22MinValue%22:%22-180%22,%22MaxValue%22:%22a%22,%22ListID
%22:%22%22,%22InputTypeID%22:%228%22,%22
Multiple%22:false,%22Required
%22:false}

05/01/2008 17:37:45 - 192.168.1.2 - get data =3D {\"FormID\":\"21\",
\"FieldsetID\":\"87\",\"XAttrID\":\"18\",\"Label\":\"Max. longitude\",
\"Units\":\"\",\"ToolTip\":\"Maximum longitude (-180 to 180). Valid
formats : 53.5, 53=B016.2, 53=B016'20.5 and 53=B016'22''.\",\"MinValue\"=
:
\"-180\",\"MaxValue\":\"a\",\"ListID\":\"\",\"InputTypeID\":\"8\",
\"Multiple\":false,\"Required\":false}


IE7 log:
05/01/2008 17:38:55 - 192.168.1.2 - url =3D /webpage.php?
action=3Dmodform&data=3D{"FormID":"21","FieldsetID":"87","XAttrID":"18","Lab=
el":"Max.
%20longitude","Units":"","ToolTip":"Maximum%20longitude%20(-180%20to
%20180).%20Valid%20formats%20:%2053.5,%2053=B016.2,%2053=B016'20.5%20and
%2053=B016'22''.","MinValue":"-180","MaxValue":"a","ListID":"","InputTypeID"=
:"8","Multiple":false,"Required":false}

05/01/2008 17:38:55 - 192.168.1.2 - get data =3D {\"FormID\":\"21\",
\"FieldsetID\":\"87\",\"XAttrID\":\"18\",\"Label\":\"Max. longitude\",
\"Units\":\"\",\"ToolTip\":\"Maximum longitude (-180 to 180). Valid
formats : 53.5, 53=B016.2, 53=B016'20.5 and 53=B016'22''.\",\"MinValue\"=
:
\"-180\",\"MaxValue\":\"a\",\"ListID\":\"\",\"InputTypeID\":\"8\",
\"Multiple\":false,\"Required\":false}


thanx in advance,

Pugi!
Pugi!

2008-01-05, 7:00 pm

I've expiremented a bit with escape for javascript and urlencode for
PHP.
They have a different outcome for =B0 (symbol for degrees):
java script: %B0
PHP: %C2%B0
Could this be the cause for my problems ?

Pugi!

On 5 jan, 18:04, "Pugi!" <pugin...@gmail.com> wrote:
> Hi,
>
> I am having a problem that is occuring when using php, json, utf-8
> charset and IE7.
> It sounds like a browser (thus client side) problem but since it is
> occuring on a php driven website, I think the best help I can get is
> here.
> Given: webpage (valid XHTML, utf-8 charset) with form (I use the YUI
> dialog), using javascript I collect all the user input on the form,
> store it in an object, json encode it, send it to the server (AJAX
> GET, no form submit), json decode it, validate and sanitize it, store
> it in database when ok, otherwise create error message and send
> response back to the client.
> The problem occures when the user inputs coordinates like 53=B016'35''.
> which is allowed. It works fine with FF, Safari and Opera, but not
> with IE7 (dont' know for IE6). Before the request is send to the
> server I visualize the json encoded information and the url with
> querystring in an alert and there is no difference here between IE7
> and other browsers, but once it arrives on the server there is a
> difference:

J.O. Aho

2008-01-05, 7:00 pm

Pugi! wrote:
> I've expiremented a bit with escape for javascript and urlencode for
> PHP.
> They have a different outcome for ° (symbol for degrees):
> java script: %B0
> PHP: %C2%B0
> Could this be the cause for my problems ?


Sure that will make a difference, I guess you have UTF-8 on the PHP side while
on the javascript uses ISO8859-1



--

//Aho
Pugi!

2008-01-06, 7:59 am

On 5 jan, 20:40, "J.O. Aho" <u...@example.net> wrote:
> Pugi! wrote:
>
> Sure that will make a difference, I guess you have UTF-8 on the PHP side w=

hile
> on the javascript uses ISO8859-1
>
> --
>
> //Aho


No both have utf-8. For JSON I used a script I found on the internet
and the YUI JSON (beta), both have same errors.
There is something in the way IE7 sends the data that makes it
impossible to process by json_decode. Using escape en urldecode,
nothing works anymore.

Any ideas ?

Pugi!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com