【问题标题】:Twilio sms verification: Your verification code is incorrectTwilio 短信验证:您的验证码不正确
【发布时间】:2016-08-27 10:36:09
【问题描述】:

我使用 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);
}

?>

感谢您的帮助!

【问题讨论】:

标签: php indexing sms undefined twilio


【解决方案1】:

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

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

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

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

  • 似乎有时代码是空字符串,并且在这种情况下未定义变量“$numbers”。 if 之前写 $numbers = [];

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

  • 请参阅之前的评论,因为这种情况完全相同。

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

  • 您使用仅包含一项“代码”的数组调用 get_sms_numbers。您也应该使用 isset()。

【讨论】:

  • 你能把修改后的代码发给我吗?我是初学者。
猜你喜欢
  • 1970-01-01
  • 2012-04-11
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
  • 2016-08-10
  • 2016-07-27
  • 2014-01-08
  • 2021-01-21
相关资源
最近更新 更多