Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.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
reCAPTCHA和Dropzone JS_Recaptcha_Dropzone.js - Fatal编程技术网

reCAPTCHA和Dropzone JS

reCAPTCHA和Dropzone JS,recaptcha,dropzone.js,Recaptcha,Dropzone.js,有没有可能将Meno不可思议的功能结合起来,以防止攻击和阻止垃圾邮件机器人?使用wordpress。 这是我在以下几个教程中想到的: 还有一些我不记得了 // Dropzone.autoDiscover = false; //I use Autodiscover Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element // The configuration

有没有可能将Meno不可思议的功能结合起来,以防止攻击和阻止垃圾邮件机器人?

使用wordpress。 这是我在以下几个教程中想到的:

  • 还有一些我不记得了

    // Dropzone.autoDiscover = false; //I use Autodiscover
    Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element
    
    // The configuration we've talked about above
    autoProcessQueue: false,
    uploadMultiple: true,
    parallelUploads: 100,
    maxFiles: 100,
    previewsContainer: '.fileupload',
    
    // The setting up of the dropzone
    init: function() {
        var myDropzone = this;
    
        // First change the button to actually tell Dropzone to process the queue.
        this.element.querySelector("input[type=submit]").addEventListener("click", function(e) {
            // Make sure that the form isn't actually being sent.
            e.preventDefault();
            e.stopPropagation();
            // myDropzone.processQueue();
    
            var valid = true;
            $('[data-required]').each(function(i,ele){
                if(ele.value == ''){
                    $(this).parent().parent().addClass('alert');
                    valid = false;
                }
            });
            if (!valid){
                e.preventDefault();
                scrollTop();
                return false;
            }
    
            // Get the recaptcha input
            var cap_input = grecaptcha.getResponse();
            $.ajax({
                url: homeUrl+'/wp-admin/admin-ajax.php',
                type: "POST",
                dataType: "JSON",
                data: {
                    "action": "verifyReCaptcha",
                    "g-recaptcha-response": cap_input
                },
                success: function(response){
                    console.log(response);
    
                    if(response == 'Good captcha'){
    
    
                        if (myDropzone.getQueuedFiles().length > 0) {
                            myDropzone.processQueue();
                        }
                        else {
                            // Upload anyway without files
                            if (wantToUpload == 'unknown') {
                                $('#noFiles').modal();
                                e.preventDefault();
                                return false;
                            }
                            else if (wantToUpload == false) {
                                myDropzone.uploadFiles([ ]);
                            }
                            else {
                                myDropzone.uploadFiles([ ]);
                            }
                        }
                    }
                    else{
                        console.log('Spammer go away');
                        $('.g-recaptcha').addClass('alert');
                    }
                }
            });
        });
    
        // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
        // of the sending event because uploadMultiple is set to true.
        this.on("sendingmultiple", function() {
        // Gets triggered when the form is actually being sent.
        // Hide the success button or the complete form.
        console.log('sending');
    });
        this.on("successmultiple", function(files, response) {
        // Gets triggered when the files have successfully been sent.
        // Redirect user or notify of success.
        console.log('success');
    });
        this.on("errormultiple", function(files, response) {
        // Gets triggered when there was an error sending the files.
        // Maybe show form again, and notify user of error
        console.log('error');
    });
    }
    }
    
还有一些html/php

<form name="" action="<?=get_permalink();?>" method="post" id="my-awesome-dropzone" class="dropzone" enctype="multipart/form-data">
    <label class="label" for="text-435">
        <?=__('Name*','gt_domain');?>
    </label>
    <input type="text" name="client-name" value="" size="40" class="input__field--manami" id="text-435" data-required="true">

    <!-- Lots of input fields -->

    <div class="col-md-8 col-xs-12 fileupload dropzone-previews dz-message">
        <h2 class="text-center" id="fileuploadtext">
            <?=__('Click or drag and drop your file here <br>(Max 60mb)','gt_domain');?>
        </h2>
    </div>
    <div class="g-recaptcha" data-sitekey="MY_PUBLIC_KEY"></div>
    <input class="dangerzone-submit" type="submit" value="<?=__('Request quote','gt_domain');?>" name="dangerzone-submit">
</form>
并最终接收表单输入和图像:

<?php
if (isset($_POST['dangerzone-submit'])) {
    // print_r($_POST);
    $client = $_POST['client-name'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $phone = $_POST['phone'];
    $comments = $_POST['comments'];



    if ($_FILES) {
        foreach ($_FILES as $file => $array) {
            // print_r($array);
            if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK &&  $_FILES[$file]['error'][0] !== 0) {
                echo "upload error : \n";
                print_r($_FILES[$file]['error']);
                print_r($_FILES);
                die();
            }
            $uploads_dir = ABSPATH . 'wp-content/uploads/dropzone/';
            $external_link = get_home_url().'/wp-content/uploads/dropzone/';

            foreach ($array['name'] as $key => $val) {
                print_r($key);
                $name = $array['name'][$key];
                $tmp_name = $array['tmp_name'][$key];
                $newfilename = wp_unique_filename( $uploads_dir, $name );

                $movefile = move_uploaded_file($tmp_name, $uploads_dir.$newfilename);
                $uploaded_files[] = $external_link.$newfilename;
            }
        }
    }


    sendMail( //My func for sending mail
            $client,
            $email,
            $company,
            $phone,
            $comments,
            $uploaded_files
        );

}
?>

客户端“verifyReCaptcha”是一种非常糟糕的模式,保护api调用的唯一方法是对来自Google的令牌进行后端/服务器端验证。任何人都可以通过绕过验证来调用端点。
<?php
if (isset($_POST['dangerzone-submit'])) {
    // print_r($_POST);
    $client = $_POST['client-name'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $phone = $_POST['phone'];
    $comments = $_POST['comments'];



    if ($_FILES) {
        foreach ($_FILES as $file => $array) {
            // print_r($array);
            if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK &&  $_FILES[$file]['error'][0] !== 0) {
                echo "upload error : \n";
                print_r($_FILES[$file]['error']);
                print_r($_FILES);
                die();
            }
            $uploads_dir = ABSPATH . 'wp-content/uploads/dropzone/';
            $external_link = get_home_url().'/wp-content/uploads/dropzone/';

            foreach ($array['name'] as $key => $val) {
                print_r($key);
                $name = $array['name'][$key];
                $tmp_name = $array['tmp_name'][$key];
                $newfilename = wp_unique_filename( $uploads_dir, $name );

                $movefile = move_uploaded_file($tmp_name, $uploads_dir.$newfilename);
                $uploaded_files[] = $external_link.$newfilename;
            }
        }
    }


    sendMail( //My func for sending mail
            $client,
            $email,
            $company,
            $phone,
            $comments,
            $uploaded_files
        );

}
?>