| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
|
I'm trying to send an XML document from a flash movie to a PHP3 script via post. I'm having trouble recieving the posted XML on the PHP end. The Script I have reports the the $HTTP_POST_VARS is a string but is empty. I also tried looking for a temp file but no luck there either. Can anyone help?
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,612
|
Try changing the Variable method to GET for debugging. that way you can see the XML being passed in the URL bar.
Cheers Jesse
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Jan 2001
Posts: 2
|
Assuming he's sending it through the XML.send() method, he can't send it GET.
The problem is that Flash is sending the XML without a name. PHP is doing some "funny" conversion. It is trying to split it into name value pairs <person name="fred"> <age>29</age> <person> becomes NAME = <person_name VALUE = "fred"><age>29</age><person> go figgure Neeld |
|
|
|
|
|
#4 |
|
Registered User
|
I figured it out. What it was is that I was not using the swf in an HTML file. You can't simply test the swf within flash you have to use in inside a browser window (f12) for it to actually send the XML. Only then will it be avalible as the $HTTP_POST_VARS variable.
|
|
|
|
|
|
#5 |
|
Registered User
Join Date: Jul 2001
Posts: 7
|
How did you guys fix the problem with php spliting xml into name value pairs ?
I more or less have this: <? $filename = "xmloutput.txt"; $fp = fopen( $filename,"w+"); while( list($key, $val) = each($HTTP_POST_VARS) ){ fwrite( $fp, "$key :: $val \n"); } fclose( $fp ); ?> and I get odd things like this: (KEY , VALUE) <LOGIN_password :: \"barkbark\" username=\"myDog\" /> when it should look likes this: <LOGIN password="barkbark" username="myDog" /> Any ideas folks ? URL encoding and loadVariables I know how to do, but this xml thing is really confusing me. -- Wolf [Edited by wolf on 07-16-2001 at 02:42 PM] |
|
|
|
|
|
#6 |
|
Registered User
|
all I can say is, when getting output from other applications, you usually have to parse out alot of things.
It looks like your going to have to use stripslashes(), and a few str_replace()'s . Good Luck |
|
|
|
|
|
#7 |
|
Registered User
Join Date: Jul 2001
Posts: 7
|
Posting this to be thorough. This is what I found:
In PHP $HTTP_RAW_POST_DATA only exists when the mime type of the POST is unrecognized. This is a problem when it's flash submitting XML. Here's a informative link: http://marc.theaimsgroup.com/?l=php-...3317720300&w=2 Apparently it's a PHP limitation and has nothing to do with Flash. Unsure if the PHP developers plan on a fix. -- WOLF |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Jul 2001
Posts: 7
|
Posting this to be thorough. This is what I found:
Supposively, since XML is not normal url encoded post data - it should be stored in $HTTP_RAW_POST_DATA. But... In PHP $HTTP_RAW_POST_DATA only exists when the mime type of the POST is unrecognized. This is a problem when it's flash submitting XML. Here's a informative link: http://marc.theaimsgroup.com/?l=php-...3317720300&w=2 Apparently it's a PHP limitation and has nothing to do with Flash. Unsure if the PHP developers plan on a fix. -- WOLF |
|
|
|
|
|
#9 |
|
Registered User
Join Date: Jul 2001
Posts: 11
|
This is NOT a problem with PHP. Flash is sending meta information that does not match the content of the data it's sending. The application/x-www-form-urlencoded content-type is reserved exclusively for data that is actually url encoded (which xml data from Flash is not). I actually wish it was something wrong with PHP, because it would get fixed a lot faster if it was!
Anyway the kludge is to do some parsing in PHP before invoking the XML engine. The faulty content-type is causing PHP to parse the data as if it were url encoded ('attribute1=value1&attribute2=value2...') and place it in $HTTP_POST_VARS instead of $HTTP_RAW_POST_DATA where the XML engine expects it. It's trivial to set things right once you know what's gone wrong: $s = ''; while(list($key, $val) = each($HTTP_POST_VARS)) { $s .= $key . '=' . $val; } $s = str_replace('_', ' ', stripslashes($s)); $HTTP_RAW_POST_DATA = $s; Then just proceed as normal, invoking your XML parser of choice... BTW, anyone interested in building XML clients and servers with Flash and PHP should take a look at XML-RPC (Remote Procedure Call) at http://www.xml-rpc.com. There are helpful ActionScript and PHP libraries that make this much easier (after you use the above fix!). Good luck, doug ![]() |
|
|
|
|
|
#10 |
|
Registered User
Join Date: Jul 2001
Posts: 7
|
Well, I have two tidbits of information. Thanks to nicewebguy for reminding of of the content issue.
You should not have to have a php script that parses the data back together if you set the content type of the xml to "text/xml". This was a bug in version 5,0,30,0 (the initial released version with the dev studio). See link: http://www.macromedia.com/support/fl...ntent_type.htm It always sends a content type of "application/x-www-form-urlencoded". But in version 5,0,42,0 (only through the webbrowser) of the player you have a new XML member called contentType that I can set the type to "text/xml". Now, when I do this $HTTP_RAW_POST_DATA will be set with my XML and not chopped into nasty key value pairs. And the second minor tidbit, for PHP developers: In version 4.0.7 there will be a config directive to force $HTTP_RAW_POST_DATA to stay set no matter what. For those of you interested, here's my code (and it seems to work for me - heavily borrowed from macromedia example): Flash: on (release) { // A. Construct a XML document with a LOGIN element loginXML = new XML(); loginElement = loginXML.createElement("LOGIN"); loginElement.attributes.username = "MyDog"; loginElement.attributes.password = "barkbark"; loginXML.appendChild(loginElement); // this only works in version 5,0,42,0 or greater (test in web browser) loginXML.contentType = "text/xml"; // B. Construct a XML object to hold the server's reply loginReplyXML = new XML(); loginReplyXML.onLoad = onLoginReply; // C. Send the LOGIN element to the server, //place the reply in loginReplyXML loginXML.sendAndLoad("xmlreader.php", loginReplyXML); } xmlreader.php PHP CODE: <? // make sure you have the proper permissions to write to this file $filename = "xmloutput.txt"; $fp = fopen( $filename,"w+"); fwrite ( $fp, "$HTTP_RAW_POST_DATA" ); fclose( $fp ); print '<?xml version="1.0"?><result>LOGIN OK</RESULT>'; ?> and I end up with an xmloutput.txt file with this in it: <LOGIN password="barkbark" username="MyDog" /> Hope this helps. Thanks to everyone who helped me figure this one out. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| writing to text file via php using LoadVars | victor322 | ActionScript 2.0 | 5 | 05-10-2006 03:42 AM |
| Problem with AS and PHP, have to click button twice to return variable from php | jetgrind | ActionScript 2.0 | 5 | 10-19-2005 08:43 AM |
| LoadVars or XML with PHP on DIFFERENT servers doesn't work. | Sckz | Server-Side Scripting | 4 | 07-14-2005 12:01 AM |
| Problems loading PHP file into Flash | lrempel | ActionScript 2.0 | 1 | 01-25-2005 12:11 PM |
| how to link Action Script to a remote PHP | atomskreymx | Server-Side Scripting | 2 | 11-16-2004 07:01 AM |