Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
第一次使用PHP cURL,将API集成到签名表单的小问题_Php_Mysql_Forms_Api_Curl - Fatal编程技术网

第一次使用PHP cURL,将API集成到签名表单的小问题

第一次使用PHP cURL,将API集成到签名表单的小问题,php,mysql,forms,api,curl,Php,Mysql,Forms,Api,Curl,我正在尝试将API集成到我的签名表单中 这是我的流程表。我的目标是在api验证程序中传递电子邮件,如果状态值为400,它将通过返回错误来取消。如果状态为其他(200),则请求成功/ 429超过利率限制)另一次较弱的检查结果为真。目前,api无法正常工作,因为垃圾邮件提供商仍然可以注册 希望你能帮忙 谢谢 当API返回200响应并且电子邮件是一次性的时,您没有处理这种情况 替换此项: if($status==400){ $errors['email']='Invalid email address

我正在尝试将API集成到我的签名表单中

这是我的流程表。我的目标是在api验证程序中传递电子邮件,如果状态值为400,它将通过返回错误来取消。如果状态为其他(200),则请求成功/ 429超过利率限制)另一次较弱的检查结果为真。目前,api无法正常工作,因为垃圾邮件提供商仍然可以注册

希望你能帮忙 谢谢


当API返回200响应并且电子邮件是一次性的时,您没有处理这种情况

替换此项:

if($status==400){
$errors['email']='Invalid email address';
}否则{
如果(!filter_var($email,filter_VALIDATE_email)){
$errors['email']='Invalid email address';
//无效的电子邮件地址
}
$domain=ltrim(stristr($email,'@'),'@');
如果(!checkdnsrr($domain,'MX')){
$errors['email']='Invalid email address';
//域无效
}
}
据此:

if($status==400){
$errors['email']='Invalid email address';
}如果($status==200&&$response_data['disposable']==true),则为else{
$errors['email']='Invalid email address';
}否则{
如果(!filter_var($email,filter_VALIDATE_email)){
$errors['email']='Invalid email address';
//无效的电子邮件地址
}
$domain=ltrim(stristr($email,'@'),'@');
如果(!checkdnsrr($domain,'MX')){
$errors['email']='Invalid email address';
//域无效
}
}

它似乎在我的xampp localhost上工作,但当我导入代码时,php进程似乎执行得不好。它可以链接到我的服务器UFW防火墙或其他什么吗?我回答说:Curl并没有安装在web服务器上。sudo apt get install php curl sudo systemctl restart nginx修复了所有问题谢谢:)
<?php
require_once 'sendemails.php';
session_start();
$fname = "";
$lname = "";
$email = "";
$canada = "";
$consent = "";
$comment = "";
$errors = [];

$conn = new mysqli('localhost', '*****', '******', '******');

// SIGN UP USER
if (isset($_POST['signup-btn'])) {
    if (empty($_POST['fname'])) {
        $errors['fname'] = 'First Name required';
    }
    if (empty($_POST['lname'])) {
        $errors['lname'] = 'Last Name required';
    }
    if (empty($_POST['email'])) {
        $errors['email'] = 'Email required';
    }


    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $email = $_POST['email'];


    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.validator.pizza/email/' . $email);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
// Decode JSON into PHP array
$response_data = json_decode($response, true);
$status = $response_data['status'];
if ($status == 400) {
    $errors['email'] = 'Invalid email address';
    } else {
        
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $errors['email'] = 'Invalid email address';
    // invalid emailaddress
    }
    
    
    $domain = ltrim(stristr($email, '@'), '@') . '.';
    if (!checkdnsrr($domain, 'MX')) {
        $errors['email'] = 'Invalid email address';
    // domain is not valid
    }
}



    $canada = $_POST['canada'];
    $consent = $_POST['consent'];
    $comment = $_POST['comment'];
    $token = bin2hex(random_bytes(50)); // generate unique token

    // Check if email already exists
    $sql = "SELECT * FROM signatures WHERE email='$email' LIMIT 1";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        $errors['email'] = "Email already exists";
    }

    if (count($errors) === 0) {
        $query = "INSERT INTO signatures SET fname=?, lname=?, email=?, canada=?, consent=?, comment=?, token=?";
        $stmt = $conn->prepare($query);
        $stmt->bind_param('sssssss', $fname, $lname, $email, $canada, $consent, $comment, $token);
        $result = $stmt->execute();

        if ($result) {
            $user_id = $stmt->insert_id;
            $stmt->close();

            // TO DO: send verification email to user
            sendVerificationEmail($email, $token);

            $_SESSION['id'] = $user_id;
            $_SESSION['fname'] = $fname;
            $_SESSION['lname'] = $lname;
            $_SESSION['email'] = $email;
            $_SESSION['canada'] = $canada;
            $_SESSION['consent'] = $consent;
            $_SESSION['comment'] = $comment;
            $_SESSION['verified'] = false;
            $_SESSION['message'] = 'You have signed the petition. Please Verify Your Email address to complet the signature. / Vous avez signé la pétition. Veuillez vérifier votre adresse e-mail pour compléter la signature.';
            $_SESSION['type'] = 'alert-success';
            header('location: thankyou.php');
        } else {
            $_SESSION['error_msg'] = "Database error: Could not register user";
        }
    }
}