AS programmer needs help with php
Posted: Mon Feb 08, 2010 6:25 am
Hello!I don't know ANYTHING about PHP
,so I was wandering if somebody can help me.I have online game(AS 3.0) and I want to save score online to xml file.AS would send two variables and php would get them and add a new node to xml,something like this:
So this is my PHP script:
I just want to know is this code ok?Does it do exactly what I have described?
Because if this is ok, then I would know that I'm posting wrong vars from Actionscript...
Thanks...
Code: Select all
<player>
<name>//first var</name>
<score>//second var</score>
</player>
Code: Select all
<?php
$phpvar1 = $_POST['first'];
$phpvar2 = $_POST['second'];
$file ="scores.xml";
$fp = fopen($file, "rwx") or die("cannot open file");
$str = fread($fp, filesize($file));
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML($str) or die("Error");
echo "<xmp>OLD:\n". $xml->saveXML() ."</xmp>";
$root = $xml->documentElement;
$fnode = $root;
$ori = $fnode->childNodes->item(0);
$name= $xml->createElement("name");
$nameText = $xml->createTextNode($phpvar2);
$name->appendChild($nameText);
$result=$xml->createElement("result");
$resultText = $xml->createTextNode($phpvar1);
$result->appendChild($resultText);
$player = $xml->createElement("player");
$player->appendChild($name);
$player->appendChild($result);
$fnode->insertBefore($player,$ori);
echo "<xmp>NEW:\n". $xml->saveXML() ."</xmp>";
$XML->save('scores.xml');
?>
Because if this is ok, then I would know that I'm posting wrong vars from Actionscript...
Thanks...