PDA

Click to See Complete Forum and Search --> : [Resolved] [Resolved] communication FLASH 5 XML =>PHP with sendAndLoad



Daafy
06-04-2001, 04:11 PM
Hi all,
The objective is to send an XML var from flash using objXML.sendAndLoad to a php file and so get this var in php.
Prob : I'm not able to get the object -loginXML- with php. I tried using $HTTP_POST_VARS, I get only a piece of the xml object !!!!



//..................construction of the xml rqst var loginXML

var loginXML = new XML();
loginXML.parseXML("<LOGIN idUser='antoine' pass='154'/>");
loginXML.contentType = 'text/xml';


//................... response object preparation
var loginReplyXML = new XML();
//................... reception function
function onLoginReply()
{
this; // xml object of answer
}

//....................affecting reception function
loginReplyXML.onLoad = onLoginReply;

//....................sending the rqst to php
loginXML.sendAndLoad("http://citrus/T10/test.php",loginReplyXML);


//==========================reception with PHP==========test.PHP===============

<?
if(isset($HTTP_POST_VARS))
{
reset($HTTP_POST_VARS);
foreach($HTTP_POST_VARS as $nomvar=>$val)
{
//
}
}

?>

//================================================== ============================


It would be kind if you have a method to recept the xml object with php or if you have some infos about this. Thx.
:::: Daafy ::::

hal(var)
06-05-2001, 12:01 AM
well, I have not used PHP yet but my guess at the problems is that XML.sendAndLoad does not send variable=value pairs.
it sends only the XML data as the post reply.

either get the raw POST data, or maybe try grabbing the name of the first variable as a string.

perhaps since you are getting part of the data the PHP parameter parser is finding a = sign in the data and splitting it at that point.

snowdude
06-05-2001, 12:55 AM
i've never used the sendAndLoad command but here's my super simple solution, I'm not sure if it'll work with what your doing but it works really good if you don't have an insane amount of data:

loginXML.load("/test.php?Something1="+Something1+"&Ran="+random(999));

you can add as many things as you want that way. it sends those variables to the server, does what ever you want with it, then sends back the result's based on that data. - you can use the variable $Something1 or as many other variables as you want in your php script. i started to do it this way cause i was finding that if i didn't it'd try to send about 1 million pieces of useless xml data. oh yeah and 'Something1' has to be defined somewhere in the movie. Preferable at the begining of whatever frame or button or mc that your using the XML.load.

-but as always just a thought, it works for me.

Daafy
06-05-2001, 04:26 AM
Ok guys, thx, so I just will send vars from flash to php as normally...flash XML object isn't enought good solution for the moment, parsing time is ещ%!$*...
Thx again
:::: Daafy ::::

hal(var)
06-05-2001, 08:59 AM
in order to not send lots of garbage, I make a movie clip, an set the variables I want in it, then have it send the data to the server.

I've also done it with making my own string like you have, but then you are using GET to send the data and are limited as to the length of the data you can send. It can varies I think but I'm fairly sure it tops out at 2K max.

Using POST you can send much more. XML.sendAndLoad users POST, it is also bad to mix GET and POST in the same message, (it will often work but is not really to spec so it may not, it's up to whomever design you parameter parser)

And a last note since sendAndLoad only sends the XML document you tell it to, there is no extraneous garbage sent along with it.

capcards
06-07-2001, 03:18 PM
I just posted this on another string of postings.

I am trying to do something similar. I want to create an HTML based form on a website that will write to an XML file. I am pulling the data in that XML file into a stand alone projector flash movie. I can't seem to get the script to work correctly though. If anyone figures this out. drop me an email or post back. capcards@hotmail.com

http://html.about.com/compute/html/gi/dynamic/offsite.htm?site=http%3A%2F%2Fwww.fastnetltd.ndire ct.co.uk%2FPerl%2FXMLForm.html

Daafy
06-07-2001, 04:44 PM
Hi capscards...just tell you that it's demonstrated there are bugs about flash xml objects...particulary with sendAndLoad function...don't remember the adress, but the note is notified on macromedia website...that didn't bring to me the solution but...
work hard...

capcards
06-07-2001, 11:43 PM
Daafy, I am not trying to make the form through flash. I want to have an HTML based submission form that will write to an XML file. My problem is really in getting the perl script to work. I just thought it pertained to what this discussion was about since I was under the impression that in order to post variables to an XML document you would need to use perl or asp or some sort of server side scripting language.

Dave

John
06-16-2001, 09:06 PM
Got it !!!

In your PHP your XML Data will be found in...



$HTTP_RAW_POST_DATA


Regards,

Johny

bebopcoder
07-16-2001, 04:04 PM
The following php code doesn't seem to be working for me,



$filename = "xmloutput.txt";

$fp = fopen( $filename,"w+");

fwrite( $fp, "script started : \n");

fwrite ( $fp, $HTTP_RAW_POST_DATA );
fclose( $fp );


This is using $HTTP_RAW_POST_DATA as suggested above. I do get some stuff in $HTTP_POST_VARS but it's incorrectly split into key value pairs. Can anyone provide a very small sample script that just accepts some xml passed via flash and outputs it to a file. Or even back to the flash. Whatever. I just can't seem to find where PHP is storing the data when it gets it from an xml.send() from flash.
If someone posts a known working script, I can get an idea if it's a problem on my end or otherwise.

-- BEBOPCODER

amirk
07-27-2001, 12:50 PM
did you add any childs to the loginXml?

you should do something like this:

loginXmlElement = loginXml.createElement("yournodename");
loginXmlElement.attributes.anyname= "anyvalue";
loginXml.appendChild(loginXmlElement);

then in PHP try this (it depend on the hosting server configuration):

while(list($key, $val) = each($GLOBALS)) {
if ($key == "anyname") {
$anyPhpVarName=anyname($val);
}
// and any more needed keys...
}

hope it will help.

bebopcoder
07-27-2001, 01:25 PM
Here is something I posted on another message board and is a short explanation of how I fixed my problem (hope it helps everyone):

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/flash/ts/documents/xml_content_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:

&lt;LOGIN password="barkbark" username="MyDog" /&gt;

Hope this helps. Thanks to everyone who helped me figure this one out.
[Edited by bebopcoder on 07-27-2001 at 01:28 PM]

bobajobrob
07-28-2001, 07:31 AM
another workaround is to assing the xml to a variable then send it with loadVariables - you'll know which HTTP_POST_VAR to look for then

nu-skool
08-01-2001, 11:15 AM
Do you lot get xml.sendAndLoad to work in netscape? I can't get it to even hit the server (weblogic). It works a treat in ie.
Any advice would be greatly appreciated.

Daafy
08-01-2001, 12:07 PM
Thanks all for your participation around this subject, all posts are very usefull and advanced me up (and probably others) a lot.