2016-04-30 42 views
0

我有一個聯繫人的PHP聯繫人文件, 我在我的HTML主題下添加了reCAPTCHA,在聯繫表格 下,但我希望代碼確保客戶或想要的人聯繫通過reCAPTCHA ..!如何確保通過reCAPTCHA驗證的人

這裏是我的PHP代碼聯繫:

<? 
$name = $_POST[name]; 
$email = $_POST[email]; 
$type = $_POST[type]; 
$message = $_POST[message]; 

if ($name == "") { 
die('name null'); 
} 
if ($type == "" || $email == "" || $message == "") { 
die("not null"); 
} 

$myemail = "[email protected]"; 
$s = "$name"; 
$body = "<b>Message from Client</b> <br><br> Name: <b>$name</b><br> Package: <b>$type</b><br> E-mail: <b>$email</b><br> Message: <b>$message</b>"; 

$headers = 'From: '.$email."\r\n".'Content-Type: text/html; charset=utf-8'."\r\n"; 

mail($myemail, $s, $body, $headers); 

header('Content-Type: application/json'); 
echo json_encode(array('response' => 'success')); 
?> 

回答

0

使用if語句,檢查是否輸入了驗證碼是一樣的定義。也許粘貼形式標記?查看您正在使用哪個驗證碼?

+0

可以讓這個對我即時通訊不親PHP程序員..! –

+0

在此貼上表格的標記。所以我可以看看。 –

+0

我使用谷歌recaptcha https://www.google.com/recaptcha/intro/index.html –

0

嘗試使用這個片段來自here

<?php 
    require_once('recaptchalib.php'); 
    $privatekey = "your_private_key"; 
    $resp = recaptcha_check_answer ($privatekey, 
          $_SERVER["REMOTE_ADDR"], 
          $_POST["recaptcha_challenge_field"], 
          $_POST["recaptcha_response_field"]); 

    if (!$resp->is_valid) { 
    // What happens when the CAPTCHA was entered incorrectly 
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
    "(reCAPTCHA said: " . $resp->error . ")"); 
    } else { 
    // Your code here to handle a successful verification 
    } 
?> 
+0

,但我沒有使用recaptchalib.php文件我只有HTML的聯繫表格+ PHP文件發送表單 –