Dean
Dean

Reputation: 8065

POST from Flash (AS2) to PHP, outputs ??? when non-english characters are used

I am trying to use POST in Flash (ActionScript 2), to POST values to PHP mail script. I tried the PHP mail script with HTML form, and it worked perfectly fine.

But when I POST from flash and input non-English characters, I get "????" in the mail.

I tried utf8_encode($_POST["name"]), but it doesn't help.

Edit:

I also tried utf8_decode($_POST["name"]), it didn't work.

Update: (So you wont have to go through all the comments)

  1. I checked the variables in Flash, the values are stored correctly.
  2. The HTML page where the Flash is embedded is UTF-8 encoded.
  3. I watched the POST headers with FireBug, the POST itself is already messed up, showing "????" instead of the real value.
  4. The the messed up "????" value, is currently url-encoded by flash, and decoded by PHP, resulting in $_POST["name"] == "???";

I suspect its the sendAndLoad method that creates the mess.

Update:

Here is the flash code:

System.useCodepage = true;
send_btn.onRelease = function() {
   my_vars = new LoadVars();
   my_vars.email = email_box.text;
   my_vars.name = name_box.text;
   my_vars.family_box = comment.text;
   my_vars.phone = phone_box.text;

if (my_vars.email != "" and my_vars.name != "") {
    my_vars.sendAndLoad("http://aram.co.il/ido/sendMail.php", my_vars, "POST");
    gotoAndStop(2);
} else {
    error_clip.gotoAndPlay(2);
}
my_vars.onLoad = function() {
    gotoAndStop(3);
};
};

    email_box.onSetFocus = name_box.onSetFocus=message_box.onSetFocus=function () {
if (error_clip._currentframe != 1) {
    error_clip.gotoAndPlay(6);
}
};

Upvotes: 1

Views: 3800

Answers (2)

weltraumpirat
weltraumpirat

Reputation: 22604

Flash uses UTF8-encoding for all strings, anyway. If you use LoadVars, transfer as a urlencoded string should also work automatically.

So your problem is most probably in the PHP part of your application. For example, in order for UTF8 to work correctly, all individual PHP files must be saved in UTF8-encoded format, as well.

If just changing the file encoding doesn't work, try parsing $HTTP_RAW_POST_DATA first, check if all the fields have been transferred correctly, then go on and echo your way through until you find the place where the encoding is lost.

Update:

Here is your problem: You use System.useCodePage = true;. This requires you to specifically encode all your data as unicode before sending it. Unless you have any other documents in other encodings, and/or allow your users to upload their own text data with their localized encodings, set System.useCodePage = false;, and your utf8-problem should go away.

Upvotes: 1

Malte Köhrer
Malte Köhrer

Reputation: 1579

If you receive data from flash you need to use utf8_decode and not utf8_encode.

Flash uses UTF8 - as long as you don't tell it to use the local characterset. And you want PHP to decode that to good old ISO-8859-1 which PHP uses internally.

You'd only use utf8_encode when preparing data for flash.

Upvotes: 1

Related Questions