第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

recaptcha v2 的基本服務(wù)器集成

recaptcha v2 的基本服務(wù)器集成

PHP
千萬里不及你 2023-08-19 09:52:29
有人可以幫我解決這個問題嗎?我已經(jīng)嘗試了幾個月,但只在 YouTube 和 Google 等上遇到了令人困惑的信息。我正在為時事通訊建立訂閱表格。它只是一個電子郵件字段和一個提交按鈕。我得到了一個非常簡單的 php 代碼,該表單工作正常,但如果沒有 recaptcha,它就會暴露給機(jī)器人:<?php $email = $_POST['email'];$formcontent="From: $email \n";$recipient = "contact@myemail.com";$subject = "Subscribe";$mailheader = "From: $email \r\n";mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");echo "You have subscribed. You may close this tab now etc etc.";?>這就是我所需要的。此代碼位于 mail.php 文件中,我在表單中使用 action="mail.php",該表單位于單獨(dú)的 html 文件中。有人可以建議我添加額外的代碼來添加 SecretKey 并進(jìn)行一些基本的 recaptcha 服務(wù)器集成嗎?我無法理解 Google 信息網(wǎng)站。他們使用我從未遇到過的術(shù)語。我不知道他們想說什么。
查看完整描述

2 回答

?
九州編程

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超4個贊

如果您在表單上使用了 recaptcha,那么在提交表單時,PHP 中的 $_POST 將具有“g-recaptcha-response”。然后,您可以使用curl向Google發(fā)出API請求以驗(yàn)證他們的響應(yīng)。


以下是非?;A(chǔ)的內(nèi)容,未經(jīng)測試。您將需要做更多的工作來改善用戶體驗(yàn),例如使用 Ajax


<?php


function verifyRecaptcha($response)

{

  //Replace the below with your secret key

  $recaptchaSecret = '<google_recaptcha_secret_key>';


  $ch = curl_init('https://www.google.com/recaptcha/api/siteverify');


  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  curl_setopt($ch, CURLOPT_POST, true);

  curl_setopt($ch, CURLOPT_POSTFIELDS, array(

      'secret' => $recaptchaSecret,

      'response' => $response,

  ));


  $output = curl_exec($ch);

  curl_close($ch);


  //the response from Google will be a json string so decode it

  $output = json_decode($output);


  //one of the response keys is "success" which is a boolean

  return $output->success;

}


//First filter the POSTed data

$email = filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL);

$captchaResponse = filter_input(INPUT_POST,'g-recaptcha-response',FILTER_SANITIZE_STRING);


//If either email or catcha reponse is missing then one or both were not completed before submit

if(empty($email) || empty($captchaResponse))

{

  //TODO: Better error handling here

  echo "There was an error with the submitted data.";

}

elseif(!verifyRecaptcha($captchaResponse))  //this calls the above function to make the curl request

{

  //TODO: Better error handling here

  echo "Recaptcha verification failed.";

}

else

{

  //I would suggest you don't use their email as the "From" address, rather it should be a domain

  //that is allowed to send email from the server

  //Instead you want to use their email as the "Reply-To" address

  $formcontent = "From: $email \n";

  $recipient = "contact@myemail.com";

  $subject = "Subscribe";

  $mailheader = "From: $email \r\n";

  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

  echo "You have subscribed. You may close this tab now etc etc.";

}


查看完整回答
反對 回復(fù) 2023-08-19
?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個贊

順便說一句,這是形式:


<form class="form" action="mail5.php" method="POST">


<p class="email">

<input type="text" name="email" id="email" placeholder="mail@example.com" required />

</p>


<div class="g-recaptcha" data-sitekey="My Public Key"></div>


<p class="submit">

<input type="submit" value="Subscribe!" />

</p>

</form>

在我得到這個之前:


<script src="https://www.google.com/recaptcha/api.js" async defer></script>


查看完整回答
反對 回復(fù) 2023-08-19
  • 2 回答
  • 0 關(guān)注
  • 163 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號