簡體   English   中英

將CAPTCHA集成到現有的PHP表單中

[英]CAPTCHA integration into existing PHP form

我正在使用Google Recaptcha,而我最終得到了這段代碼。 我的目標是讓我已經工作的php表單僅在驗證碼完成后才提交。 任何幫助,將不勝感激。

<?php
if (isset($_POST['ContactButton'])) {
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $privatekey = "6LePayETAAAAANJze7opnV6bQEX-n02p4UdZ8xfF";
    $response = file_get_contents($url . "? 
        secret=" . $privatekey . "&response" . $_POST['g-recaptcha- 
        response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
    $data = json_decode($respose);
    if (isset($data -> success) AND $data -> success == true) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $message = $_POST['message'];
        $formcontent = " From: $name \n Phone: $phone \n Message: $message";
        $recipient = "magicmacaroni@gmail.com";
        $subject = "Contact Form";
        $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
        header('Location: contact-thank-you.html');
        exit();
    } else {
        header('location: index.html?captchafail=True');
    }
}
?>

您是否嘗試過使用Honeytrap而不是captcha,它更簡單並且具有相同的功能http://blog.mtstudios.net/the-honey-trap-the-easiest-way-ive-found-to-stop-spam-emails -asp-net-contact-forms /

請閱讀有關reCAPTCHAgithub頁面Google開發人員文檔,它們將對您有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM