Twilio sms验证:您的验证码不正确

时间:2016-08-27 10:36:10

标签: php indexing sms undefined twilio

我使用twilio脚本进行电话验证。在我发送了我的号码后,我总是通过短信得到代码,但我总是得到这样的信息:"您的验证码不正确"

我的错误日志中出现以下错误:

PHP Notice:  Undefined index: code in reserved.php on line 4
PHP Notice:  Undefined variable: numbers in reserved.php on line 15
PHP Notice:  Undefined index: id in /db_functions.php on line 53
PHP Notice:  Undefined index: phone in /db_functions.php on line 54
PHP Notice:  Undefined index: verified in /db_functions.php on line 56
PHP Notice:  Undefined index: start in /db_functions.php on line 57
PHP Notice:  Undefined index: nb_display in /db_functions.php on line 58
PHP Notice:  Undefined variable: jsOnReady in header.php on line 19

我在数据库中拥有所有内容..?

这里是我的reserved.php代码:

<?php
include_once('.../webzone.php');

$code = $_GET['code'];

if($code=='') $jsOnReady = "$('#code').focus();";
else $numbers = get_sms_numbers(array('code'=>$code));

include_once('.../..../header.php');
?>

<div class="container"><center>

<?php
if(count($numbers)>0) {

    if($numbers[0]['verified']!=1) {
        $m1 = new MySqlTable();
        $sql = 'UPDATE '.$GLOBALS['db_table']['sms'].' SET verified=1 WHERE code="'.$m1->escape($code).'"';
        $m1->executeQuery($sql);
    }

    include_once('locked_content.php');

}
else {
    ?>
    <h3>Your verification code</h3>
    <p class="alt" style="margin-bottom:20px;">Please enter the code you have received by SMS</p>
    <form method="GET">
    <input type="text" id="code" name="code" placeholder="Your verification code" style="padding:10px; width:300px;" value="<?php echo $code; ?>"><br>
    <input type="submit" class="btn btn-primary btn-large" value="Verify my code">
    </form>
    <?php
    if($code!='' && count($numbers)==0) {
        $message = 'Your verification code is incorrect';
        echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">x</button>'.$message.'</div>';
    }
}

?>

</center>
</div>

<?php
include_once('.../.../footer.php');
?>

这里是db_functions.php代码:

<?php

function add_history($criteria=array()) {
    $type = $criteria['type'];
    $phone = $criteria['phone'];
    $message_id = $criteria['message_id'];
    $message = $criteria['message'];
    $results = $criteria['results'];

    $m1 = new MySqlTable();
    $sql = 'INSERT INTO '.$GLOBALS['db_table']['sms_history'].' (type, phone, message_id, message, results, created) VALUES ("'.$m1->escape($type).'", "'.$m1->escape($phone).'", "'.$m1->escape($message_id).'", "'.$m1->escape($message).'", "'.$m1->escape($results).'", "'.date('Y-m-d H:i:s').'")';
    $m1->executeQuery($sql);
}

function add_sms_number($criteria=array()) {
    $phone = $criteria['phone'];
    $code = $criteria['code'];

    $m1 = new MySqlTable();
    $sql = 'INSERT INTO '.$GLOBALS['db_table']['sms'].' (phone, code, created) VALUES ("'.$m1->escape($phone).'", "'.$m1->escape($code).'", "'.date('Y-m-d H:i:s').'")';
    $m1->executeQuery($sql);
}

function get_sms_history($criteria=array()) {
    $type = $criteria['type'];
    $phone = $criteria['phone'];
    $start = $criteria['start'];
    $nb_display = $criteria['nb_display'];

    $m1 = new MySqlTable();
    $sql = "SELECT * FROM ".$GLOBALS['db_table']['sms_history']." WHERE 1 ";

    if($type!='') $sql .= " AND type='".$m1->escape($type)."'";
    if($phone!='') $sql .= " AND phone='".$m1->escape($phone)."'";

    $sql .= " ORDER BY id DESC";

    if($nb_display!='') $sql .= ' LIMIT '.$start.', '.$nb_display;

    $result = $m1->customQuery($sql);

    if($GLOBALS['demo_mode']==1) {
        for($i=0; $i<count($result); $i++) {
            $result[$i]['phone'] = substr($result[$i]['phone'], 0, -4).'xxxx';
            if($result[$i]['phone']=='') $result[$i]['phone']='xxxx';
        }
    }

    return $result;
}

function get_sms_numbers($criteria=array()) {
    $id = $criteria['id'];
    $phone = $criteria['phone'];
    $code = $criteria['code'];
    $verified = $criteria['verified'];
    $start = $criteria['start'];
    $nb_display = $criteria['nb_display'];

    $m1 = new MySqlTable();
    $sql = "SELECT * FROM ".$GLOBALS['db_table']['sms']." WHERE 1 ";

    if($id!='') $sql .= " AND id='".$m1->escape($id)."'";
    if($phone!='') $sql .= " AND phone='".$m1->escape($phone)."'";
    if($code!='') $sql .= " AND code='".$m1->escape($code)."'";
    if($verified!='') $sql .= " AND verified='".$m1->escape($verified)."'";

    $sql .= " ORDER BY id DESC";

    if($nb_display!='') $sql .= ' LIMIT '.$start.', '.$nb_display;

    $result = $m1->customQuery($sql);

    if($GLOBALS['demo_mode']==1) {
        for($i=0; $i<count($result); $i++) {
            $result[$i]['phone'] = substr($result[$i]['phone'], 0, -4).'xxxx';
            if($result[$i]['phone']=='') $result[$i]['phone']='xxxx';
        }
    }

    return $result;
}

/*
START Default add/update functions
*/

function save_posted_data($data, $table_name) {

    $s1 = new MySqlTable();

    $fields='';
    $fields_values='';
    if(count($data)>0) {
        foreach($data as $ind => $value) {
            $fields .= $s1->escape($ind).',';
            $fields_values .= "'".$s1->escape($value)."',";
        }
    }

    $fields = substr($fields,0,-1);
    $fields_values = substr($fields_values,0,-1);

    $sql = "INSERT INTO $table_name ($fields) VALUES ($fields_values)";
    $s1->executeQuery($sql);
}

function update_posted_data($data, $id, $table_name) {

    $s1 = new MySqlTable();

    $fields='';
    if(count($data)>0) {
        foreach($data as $ind => $value) {
            $fields .= $s1->escape($ind)."='".$s1->escape($value)."',";
        }
    }

    $fields = substr($fields,0,-1);
    $fields_values = substr($fields_values,0,-1);

    $sql = "UPDATE $table_name SET $fields WHERE id='".$s1->escape($id)."'";
    $s1->executeQuery($sql);
}

?>

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

一般来说,您的代码看起来很糟糕。但是,解释您的问题很容易:

  

PHP注意:未定义的索引:第4行的reserved.php中的代码

  • $ _ GET不包含代码。你应该先用isset()检查它。
  

PHP注意:未定义的变量:第15行的reserved.php中的数字

  • 似乎有时代码是空字符串和变量&#39; $ numbers&#39;在这种情况下没有定义。之前如果写$ numbers = [];
  

PHP注意:未定义的变量:第19行的header.php中的jsOnReady

  • 请参阅之前的评论,因为此案例完全相同。
  

PHP注意:未定义的索引:第53行的/db_functions.php中的id PHP   注意:未定义的索引:第54行PHP /的/db_functions.php中的电话   注意:未定义的索引:在第56行的/db_functions.php中验证PHP   注意:未定义的索引:在第57行PHP上的/db_functions.php中开始   注意:未定义的索引:第58行的/db_functions.php中的nb_display

  • 您使用仅包含一个项目&#39;代码的数组调用get_sms_numbers。你也应该使用isset()。