views:

326

answers:

4

I feel stupid asking this question, but I've been wrestling with it for hours and I don't know where else to turn.

I have a flash form that is making a POST request to a php script, and then displays the output of the said script. For the sake of simplicity, let's say this is the php script:

echo 'Mail sent to: ' . $_POST['recipientEmail'];

When I submit the form, I see this in Firebug's net tab in the line made by the POST request:

Referer: http://example.com/my.swf
Content-type: text/html
Content-length: 68

[email protected]

All well and good on the surface. The post has been made, it sent the right variable to the script. But when the response comes back, this is what I see in my Flash tracer:

Mail sent to:

In other words, the $_POST['recipientEmail'] has been lost after the request went out of my browser.

What do you think is happening here? Both the script and the swf file are in the same domain, same server.

EDIT: I just tried hitting the same script from an HTML form, and it catches the $_POST header. So it's only not catching it when it's sent by Flash. The post tab in Firebug looks a little different than it is with flash:

recipientEmail  [email protected]
submit          Submit

Notice each variable is in its own line.

EDIT: Here is the relevant AS3 code that makes the submission:

 var _gateway:String = Share.getGateway();
 var request:URLRequest;
 var variables:URLVariables = new URLVariables();
 var loader:URLLoader = new URLLoader();  

 request  = new URLRequest(_gateway);
 request.contentType = 'text/html';
 request.method = URLRequestMethod.POST;


 variables.senderName = senderName.text;
 variables.recipientEmail = recipientEmail.text;
 variables.senderMessage = senderMessage.text;

 request.data = variables;

 try {
                 loader.load(request);
 }catch (error:Error) {
      Debug.trace("Unable to load requested document.");
 }
A: 

Can you var_dump($_POST); (or print_r($_POST); ) to see what it contains?

R. Bemrose
It's empty when I do that. But see my edit, the $_POST is only empty when the form submission is made from FLash. I am going to post the relevant Flash code as well.
picardo
+3  A: 

Carefully check the headers for the request made by the HTTP form against the request from your Flash applet. At a glance, my first guess would be that "text/html" content type, which isn't correct for the data being sent — it should be "application/x-www-form-urlencoded". Mind you, I've never tested to see whether PHP actually cares about that particular detail, but it's certainly suspicious-looking.

Ben Blank
That feels right. I do have text/html set as content type. Let me check.
picardo
HURRAY! You were right. This is why I love Stackoverflow. Thanks so much.
picardo
You're very welcome. ;-)
Ben Blank
A: 

Try changing the $_POST to $_REQUEST. I've had problems before where I was expecting the information in $_POST, but it wouldn't work. Changing it to $_REQUEST brings in the values for POST, GET and COOKIE.

Sky's The Limit Software
A: 

Are you using .htaccess? Make sure that .htaccess isn't re-writing your request url. If you're sending to http://example.com and .htaccess is re-writing it to be http://example.com/, for example, you'll lose your variables.

Donnie C