phpXML Home | XML Test Sandbox | RSS Feed Example | Flash-to-PHP Example
This is the PHP code used to respond the Flash's XML request:
<?php
// include onesandzeros.biz phpXML Lite parser class
include( "phpXML.class.php" );
// lose the slashes in the XML and parse it into a new tree
$xml = new phpXML( stripslashes( $_POST['xml'] ) );
// dig out the username and password sent from Flash
$username = $xml->childNodes[0]->attributes["username"];
$password = $xml->childNodes[0]->attributes["password"];
// output the response XML back to Flash
header( "Content-type: text/xml" );
if( $password == "pokey" )
// respond positively if they send us the "good" password
echo "<response status=\"OK\">Login GOOD! Welcome to the chat system, " . $username . "!</response>";
else
// otherwise, send a bad response
echo "<response status=\"ERROR\">Login BAD. Password was inccorect (received: " . $username . ", " . $password . ").</response>";
?>
The Flash code looks like this:
stop();
var xmlRequest:XML;
var xmlResponse:XML = new XML();
xmlResponse.ignoreWhite = true;
xmlResponse.onLoad = function ( success:Boolean ) {
if( success ) {
txtStatus.text += "From PHP: ";
if( xmlResponse.firstChild.attributes.status == "OK" ) {
txtStatus.text += unescape( xmlResponse.firstChild.firstChild.nodeValue ) +
"[newline char]"
} else {
txtStatus.text += unescape( xmlResponse.firstChild.firstChild.nodeValue ) +
"[newline char]"
}
// Password was inccorect (received: '', '').
txtStatus.text += "[newline char]Raw XML:[newline char]" +
unescape( xmlResponse.toString() ) +
"[newline char]";
} else {
txtStatus.text += "ERROR: Could not connect to server.[newline char]";
}
};
mcBtnGo.onPress = function () {
txtStatus.text += "Attempting to login '" + txtUsername.text + "'...[newline char]";
xmlRequest = new XML( " " );
xmlRequest.xmlDecl = "xml=";
xmlRequest.sendAndLoad( "flashrespond.php", xmlResponse );
};
mcBtnClear.onPress = function () {
txtStatus.text = "";
};
mcBtnClear.txtLabel.text = "Clear";