Manipulando arquivo xml com simplexml - CRUD
O arquivo editar.php é responsável por alterar um nó, para isso foi obtido o nome do usuário na variável $name, dentro do loop do nó comparamos se o usuário do loop é igual ao usuário da variavel $name, caso seja, alteramos os atributos e salvamos o xml novamente.
Arquivo: editar.php
Arquivo: editar.php
<?php
include_once("config.php");
$name = $_POST["name"];
$password = $_POST["password"];
$maxconnections = $_POST["maxconnections"];
$profiles = $_POST["profiles"];
if(!$name)
exit; //Returns null
$xml = simplexml_load_file(ARQUIVO);
for($i=0; $i < count($xml->{'user-manager'}->{'auth-config'}->{'user'}); $i++) {
if(strval($xml->{'user-manager'}->{'auth-config'}->{'user'}[$i]->name) == $name) {
//$xml->{'user-manager'}->{'auth-config'}->{'user'}[$i]->name = $name
$xml->{'user-manager'}->{'auth-config'}->{'user'}[$i]->password = $password;
$xml->{'user-manager'}->{'auth-config'}->{'user'}[$i]->maxconnections = $maxconnections;
$xml->{'user-manager'}->{'auth-config'}->{'user'}[$i]->profiles = $profiles;
}
}
$xml->asXML(ARQUIVO); // XML original com o novo elemento
include "proxy.php";
?>
Novo Comentário: