我試圖安裝谷歌驗證碼爲聯繫人頁面,我已經實在有限用PHP知識安裝信息對於谷歌驗證碼。我不確定Google要求的信息應該放在我的php文件中。以下是谷歌的說明爲:的聯繫表格PHP文件
當您的用戶請在您集成驗證碼的形式,你會得到的有效載荷名爲「G-reCAPTCHA的響應」的字符串的一部分。爲了檢查是否谷歌已經驗證的用戶,發送這些參數的POST請求:
網址:https://www.google.com/recaptcha/api/siteverify
祕密(必需) - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
響應(必需) - 的「G值-recaptcha響應」。
REMOTEIP - 最終用戶的IP地址。
這裏是我的,因爲我使用的形式PHP。
<?php
$secret = 'SECRET KEY HERE';
$verificationResponse = $_POST["g-recaptcha-response"];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$verificationResponse);
$response = json_decode($response, true);
if($response["success"] === true){
// actions if successful
}else{
// actions if failed
}
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "First and Last");
$email = check_input($_POST['inputEmail'], "Required");
$phone = check_input($_POST['inputPhone']);
$message = check_input($_POST['inputMessage'], "Brief Description");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Contact Message from thewiseinvestor.net";
$message = "
Someone has sent you a message using your contact form:
Name: $name
Email: $email
Phone: $phone
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location:contact.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
HTML表單
<div class="row">
<div class="col-md-6 message">
<h2>Send Us A Message</h2>
<form name="contactform" method="post" action="index.php" class="form-vertical">
<div class="form-group">
<label for="inputName" class="control-label">Name</label>
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="First and Last">
</div>
<div class="form-group">
<label for="inputEmail" class="control-label">Email*</label>
<input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Required">
</div>
<div class="form-group">
<label for="inputPhone" class="control-label">Phone Number</label>
<input type="text" class="form-control" id="inputPhone" name="inputPhone" placeholder="Optional">
</div>
<div class="form-group">
<label for="inputMessage" class="control-label">Message</label>
<textarea class="form-control" rows="5" id="inputMessage" name="inputMessage" placeholder="Brief Description"></textarea>
</div>
<div class="g-recaptcha" data-sitekey="DATA SITE KEY HERE"></div>
<div class="form-group">
<button type="submit" class="btn btn-custom pull-right hvr-underline-from-left">Send</button>
</div>
</form>
</div> <!-- end col-md-6 -->
我到哪裏了上述信息應該去真的不確定。任何援助非常感謝。
謝謝@Ruslan Abuzant。這確實有幫助。我將在你陳述的地方添加以下內容,對於另一個愚蠢的問題抱歉,所需的谷歌密鑰,上面的內容將在哪裏出現? – user3786102
不用擔心,只需編輯剪切的代碼併爲您提供一個簡單地複製粘貼密鑰的位置。正如你所看到的那樣,它以'$ secret'的形式傳遞給google驗證URL。 –
我快到了@Ruslan Abuzant。我更新了我的php以反映你所建議的改變。我也粘貼了我的html表單。當我點擊發送時,我收到了與第6行有關的3個錯誤。**警告:通過/nfs/c12/h08/mnt/215915/domains/thewiseinvestor.net/html/index.php第6行中的allow_url_fopen = 0,在服務器配置中禁用了file_get_contents():https:// wrapper * * – user3786102