2017-04-06 7 views
0

を追加する静的なWebサイトにreCAPTCHA V2モジュールを追加しようとしているのはすでに1週間です。 (私はweb-devの経験がないので、html5テンプレートを購入しました)。私のHTML部分ですreCAPTCHA V2

<form action="include/sendmail.php" method="post"> 
    <div class="field"> 
    <label class="required" for="sc_contact_form_username">Name</label> 
    <input type="text" name="username" id="sc_contact_form_username" /> 
    </div> 
    <div class="field"> 
    <label class="required" for="sc_contact_form_email">Email</label> 
    <input type="text" name="email" id="sc_contact_form_email" /> 
    </div> 
    <div class="field message"> 
    <label class="required" for="sc_contact_form_message">Your Message</label> 
    <textarea name="message" id="sc_contact_form_message"></textarea> 
    </div> 
    <div class="g-recaptcha" data-theme="dark" data-sitekey="MYKEY"></div> 
    <div class="button"> <a class="enter" href="#"><span>Submit</span></a> </div> 
</form> 
<div class="result sc_infobox"></div> 

これまでのところは良い...私のために難しい部分もありますPHP、どのように私は検証を追加し、それをより安全にするために、現在のPHPを変更しますか?

<?php 
global $_REQUEST; 
$response = array('error'=>''); 

    $user_name = substr($_REQUEST['user_name'], 0, 20); 
    $user_email = substr($_REQUEST['user_email'], 0, 40); 
    $user_msg = $_REQUEST['user_msg']; 

    $contact_email = '[email protected]'; 

    if (trim($contact_email)!='') { 
     $subj = 'Message from ShiftCV HTML'; 
     $msg = "Name: $user_name 
     E-mail: $user_email 
     Message: $user_msg"; 

     $head = "Content-Type: text/plain; charset=\"utf-8\"\n" 
      . "X-Mailer: PHP/" . phpversion() . "\n" 
      . "Reply-To: $user_email\n" 
      . "To: $contact_email\n" 
      . "From: $user_email\n"; 

     if ([email protected]($contact_email, $subj, $msg, $head)) { 
      $response['error'] = 'Error send message!'; 
     } 
    } else 
      $response['error'] = 'Error send message!'; 

    echo json_encode($response); 
    die(); 

?> 

答えて

0

私はあなたが必要な呼び出しを行うとreCAPTCHAののREPONSEを検証するために、あなたのアプリケーションに追加することができ、このcomposserを見てお勧めします:https://github.com/google/recaptcha

+0

は、それが外部ライブラリなしで実装するのは本当に難しいですか? –

関連する問題