Visualizzazione dei risultati da 1 a 2 su 2

Discussione: login xml

  1. #1

    login xml

    Allora ho un file xml : utenti.xml strutturato cosi

    <?xml version="1.0" encoding="iso-8859-1"?>
    <Users>
    <user id="1" username="Nome" password="pass">
    // altri tag che ometto
    </user>
    </Users>

    Ora dovrei effetturare la login e provo con questo codice
    <?php
    Codice PHP:
    $file_utenti "../data/utenti.xml";

    //$username=$_POST["username"];
    //$password=$_POST["password"];

    $username="nome";
    $password="pass";

    $resultfalse;
    $structure = array();

    if (
    file_exists($file_utenti)) {
        
    // trasformiamo l'XML utenti in array
    $structure xml_to_array($file_utenti);
        
    // cerchiamo l'user e password passate
        
    $result find_user($username$password$structure);

        if (
    $result) {
            echo 
    "&response=true";
        } else {
            echo 
    "&response=false";
        }

    } else {
        exit(
    "Failed to open '$file_utenti'.");
    }

    function 
    find_user($username$password$struct) {
        
    $i 0;
        foreach (
    $struct['children'] as $user) {
            if (
    $user['attributes']['username'] == $username) {
                if (
    $user['attributes']['password'] == $password) {
                    return 
    true;
                }
            }
        }
        return 
    false;
    }

    function 
    xml_to_array$file )
    {
        
    $parser xml_parser_create();
        
    xml_parser_set_option$parserXML_OPTION_CASE_FOLDING);
        
    xml_parser_set_option$parserXML_OPTION_SKIP_WHITE);
        
    xml_parse_into_struct$parserfile_get_contents($file), $tags );
        
    xml_parser_free$parser );

        
    $elements = array();
        
    $stack = array();

        foreach ( 
    $tags as $tag )
        {
            
    $index count$elements );
            if ( 
    $tag['type'] == "complete" || $tag['type'] == "open" )
            {
                
    $elements[$index] = array();
                
    $elements[$index]['name'] = $tag['tag'];
                
    $elements[$index]['attributes'] = $tag['attributes'];
                
    $elements[$index]['content'] = $tag['value'];

                if ( 
    $tag['type'] == "open" )
                {
                    
    # push
                    
    $elements[$index]['children'] = array();
                    
    $stack[count($stack)] = &$elements;
                    
    $elements = &$elements[$index]['children'];
                }
            }

            if ( 
    $tag['type'] == "close" )
            {
                
    # pop
                
    $elements = &$stack[count($stack) - 1];
                unset(
    $stack[count($stack) - 1]);
            }
        }
        return 
    $elements[0];
    }
    ?> 
    Ho PHP 4.3.10 istallato con EasyPhp..

    mi da questo errore

    Notice: Undefined index: attributes in c:\programmi\easyphp1-8\www\dev\php\login.php on line 59

    la linea 59 è $elements[$index]['attributes'] = $tag['attributes'];

    non capisco perchè

  2. #2
    ok nessuno mi può aiutare.. cosa ho scritto di cosi sbagliato..

    cmq cercherò su google..o altre risorse..

    grazie a tutti..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.