通过PHP保存到XML

Save to XML via PHP

本文关键字:XML 保存 PHP 通过      更新时间:2023-09-26

好吧,我可能做错了100%PHP到XML有问题,我只是想保存客户的详细信息。。。。。。。(不试图确保安全,但只是学习如何做到这一点)

Html是一种简单的形式
用于名字、姓氏、密码、电子邮件和可选电话号码(目前不需要)

PHP代码是在javascript通过javascript调用它之后启动的。。

PHP

<?php
            // header('Content-Type: text/xml');
                session_register('Customer');
                //session_start('customer'); 
            $doc = new DOMDocument();
            $doc->load('customer.xml');
            $firstname = $_GET["firstName"];
            $lastname = $_GET["lastName"];
            $email = $_GET["email"];
            $password = $_GET["password"];
            $MDA = $_SESSION["Customer"]; //assign the session varaible to MDA

            if (isset($firstname)) {
            $customerArray = array();
            $customerArray['firstname'] = $firstname;
            $customerArray['lastname'] = $lastname;
            $customerArray['email'] = $email;
            $customerArray['password'] = $password;
            $MDA[$firstname] = $customerArray;
            $_SESSION["Customer"] = $MDA;
                ECHO (toXml($MDA)); 
            }

            function toXml($MDA)
            {                    
                $doc = new DomDocument('1.0');
                $Customer = $doc->createElement('Customers');
                $Customer = $doc->appendChild($Customer);
                $root = $doc->appendChild($doc->createElement('Root'));
                foreach ($MDA as $a => $b)
                {
                    $nodeA = $doc->createElement('NodeA');
                    $root->appendChild($nodeA);
                    $nodeA->appendChild($attr1);
                    $attr1 = $doc->createAttribute('firstname');
                    $attr1->appendChild($doc->createTextNode($a['firstname']));
                $attr = $doc->createElement('firstname');
                $attr = $Customer->appendChild($person);
                $lastname = $doc->createElement('lastname'); 
                $lastname = $person->appendChild($lastname);   
                $value = $doc->createTextNode($a);
                $value = $lastname->appendChild($value);
                $email = $doc->createElement('email');
                $email = $person->appendChild($email);
                $value2 = $doc->createTextNode($b['email']);
                $value2 = $email->appendChild($value2);
                $password = $doc->createElement('password');
                $password = $person->appendChild($password);
                $value3 = $doc->createTextNode($b['password']);
                $value3 = $password->appendChild($value3);        
              }
                $doc->formatOutput = true; 
                $strXml = $doc->saveXML();
                //$doc->save('customer.xml'); 
                return $strXml;
            }
        ?>

不确定是否需要,但javascript。。。它只是检查atm 的密码

var xHRObject = false;
        if (window.XMLHttpRequest)
            xHRObject = new XMLHttpRequest();
        else if (window.ActiveXObject)
            xHRObject = new ActiveXObject("Microsoft.XMLHTTP");

        function test() 
        {
            var firstname = document.getElementById("firstName").value;
            var lastname = document.getElementById("lastName").value;
            var email = document.getElementById("email").value;
            var password = document.getElementById("password").value;
            var password2 = document.getElementById("password2").value;
            var number = document.getElementById("pNumber").value;
            var type = "";
            var input = document.getElementsByTagName("input");
              xHRObject.open("GET", "testregristation.php?", true);
              xHRObject.onreadystatechange = function() {
                   if (xHRObject.readyState == 4 && xHRObject.status == 200)
                    if (password != password2) {
                    alert("Password is wrong");
                    }
                    else
                    {
                        alert("test " +firstname + " " +  lastname + " " + email + " : " + password);
                       document.getElementById('information').innerHTML = xHRObject.responseText;
              }
              xHRObject.send(); 
        };
        }

浏览器过期问题,这在Firefox 中运行良好