为什么来自服务器(PHP)的echo会向respose添加额外的xml信息


Why does the echo from the server(PHP) adds additional xml information to the respose?

我独立检查了服务器端的调试,它正常工作它正在创建一个由0和1组成的字符串,并将其发送回客户端。

在服务器端,它看起来是这样的:

    if (validateInput($_POST["user"],
                  $_POST["password1"],
                  $_POST["password2"],
                  $_POST["email1"],
                  $_POST["email2"]))
{
    $_subscriber =  new subscriber($_POST["user"],$_POST["password1"],$_POST["email1"],CURRENT_TIME);
    subscriberInsertion($_subscriber);
}
/** function subscriberInsertion($_subscriber) insert a subscriber to DB*/
function subscriberInsertion($_subscriber)
{
    $query = "INSERT INTO users (user,value,email,date) VALUES('{$_subscriber->getUser()}',
                                                              '{$_subscriber->getPassword()}',
                                                              '{$_subscriber->getEmail()}',
                                                              '{$_subscriber->getDate()}')";
    $dbObj = new DB_MySQL(DB_users_HOST,DB_users_USER,DB_users_PASS,DB_users_NAME);
    if ($dbObj ->execute($query))
    {
        header('Location:' . URL_HTML_PATH . "index.html");
        exit;
    }
}

/**validateInput main function for validation of good credntails and emails */
function validateInput($user,$pass1,$pass2,$email1,$email2)
{
    $regexUser = "/^(?=.{1,20}$)[a-zA-Z0-9]+$/";      //all letters ad number and size between 1-20
    $regexPwd = "/^(?=.*'d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$/"; //Password must contain 6-10 characters and
                                                             // at least one number, one letter and one
    //Regex mail
    $regexMail = "/^(([^<>()[']''.,;:'s@'"]+('.[^<>()[']''.,;:'s@'"]+)*)|('".+'"))@(('[[0-9]{1,3}'.[0-9]{1,3}'.0-9]{1,3}'.[0-9]{1,3}'])|(([a-zA-Z'-0-9]+'.)+[a-zA-Z]{2,}))$/";
    $response = "";
    //check user name//
    $response = $response . checkRegex($regexUser,$user); //at location 0 in string
    //check password//
    $response = $response . checkRegex($regexPwd,$pass1); //at location 1 in string
    $response = $response . textCompare($pass1,$pass2); //at location 2 in string
    //check mail//
    $response = $response . checkRegex($regexMail,$email1); //at location 3 in string
    $response = $response . textCompare($email1,$email2); //at location 4 in string
    //check user name existence

    $response = $response . checkExistaneceOfUser($user); //at location 5 in string
    echo $response;
}

您可以看到echo $response在最后返回一个由0和1组成的字符串。

在客户端,是java脚本发送带有params的请求并等待响应:

/**function checkUserExistance(str) to check if user exist*/
function sendToValidation(data)
{
    var xmlhttp;
    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var response = xmlhttp.responseText;
            alert(response);

         }
    }

     xmlhttp.open("POST",url + page,true);
     xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlhttp.send(data);
}

我从服务器端得到的响应很好,问题是我收到了一个奇怪的大xml:

<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: email2 in D:'wamp'www'MyHome2'php'databasebuilder.php on line <i>25</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>163616</td><td bgcolor='#eeeeec'>{main}( )</td><td title='D:'wamp'www'MyHome2'php'databasebuilder.php' bgcolor='#eeeeec'>..'databasebuilder.php<b>:</b>0</td></tr> </table></font> 001011"

我只放了xml的一小部分,因为它太大了,正如你在xml的末尾看到的,我得到了001011,这是我期望的响应。为什么我得到这个xml和我的结果?我该如何摆脱它?

您看到的是xDebug的输出。

当您出现php错误时,会显示此信息。

错误来自代码样本的第5行

代码:$_POST["email2"]

错误:Notice: Undefined index: email2

提交表单时,您不会通过POST发送email2的值。

您可以使用isset解决此问题(http://php.net/manual/en/function.isset.php)在调用验证函数

之前