Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Supporting Technologies > Server-Side Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-07-2001, 02:37 PM   #1
indirect
Registered User
 
Join Date: Jan 2001
Location: Lex KY
Posts: 16
Send a message via AIM to indirect
Arrow

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?
indirect is offline   Reply With Quote
Old 02-09-2001, 11:13 AM   #2
Jesse
Administrator
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: Australia
Posts: 8,612
Default

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.
Jesse is offline   Reply With Quote
Old 03-04-2001, 10:29 AM   #3
neeld
Registered User
 
Join Date: Jan 2001
Posts: 2
Post

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

neeld is offline   Reply With Quote
Old 03-05-2001, 01:29 PM   #4
indirect
Registered User
 
Join Date: Jan 2001
Location: Lex KY
Posts: 16
Send a message via AIM to indirect
Arrow I figured it out

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.
indirect is offline   Reply With Quote
Old 07-16-2001, 08:35 PM   #5
wolf
Registered User
 
Join Date: Jul 2001
Posts: 7
Default Problem with PHP splitting up the xml

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]
wolf is offline   Reply With Quote
Old 07-17-2001, 01:27 PM   #6
indirect
Registered User
 
Join Date: Jan 2001
Location: Lex KY
Posts: 16
Send a message via AIM to indirect
Default

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
indirect is offline   Reply With Quote
Old 07-17-2001, 03:17 PM   #7
wolf
Registered User
 
Join Date: Jul 2001
Posts: 7
Default Here's part of the problem....

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
wolf is offline   Reply With Quote
Old 07-17-2001, 03:18 PM   #8
wolf
Registered User
 
Join Date: Jul 2001
Posts: 7
Default Here's part of the problem....

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
wolf is offline   Reply With Quote
Old 07-17-2001, 06:36 PM   #9
nicewebguy
Registered User
 
Join Date: Jul 2001
Posts: 11
Default Fix for crazy XML parsing

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
nicewebguy is offline   Reply With Quote
Old 07-17-2001, 08:40 PM   #10
wolf
Registered User
 
Join Date: Jul 2001
Posts: 7
Default Two things..... (PHP and XML with Flash)

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.
wolf is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 09:21 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.