I wrote an HTTP request that mobile devices send their respective tokens to the server, an this code on the server checks a XML file if the token was already registered. If so, it does nothing, if not, it adds the new token to the XML.
When when saving (maybe because there are many people trying to access at the same time), the xml gets truncated, like this:
<root> <token> 123456 </token> <token> 234567 </token> <token> 345678 </to
What shall be happening?
The code is something like this:
if( !ini_get('safe_mode') ){
set_time_limit(0);
}
if (file_exists("tokens.xml"))
{
$xml = simplexml_load_file("tokens.xml");
if ($xml)
{
$found = false;
foreach($xml->children() as $child)
{
if ($_POST['token'] == $child)
{
$found = true;
break;
}
}
if ($found)
echo $_POST['token'];
else
{
$xml->addChild("token", $_POST['token']);
unlink("tokens.xml");
$xml->saveXML("tokens.xml");
echo $_POST['token'];
}
}
else
echo "Error";
}