Google reCAPTCHA使用方式

有關網頁及相關語法的討論
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

Google reCAPTCHA使用方式

文章 tim »

參考這篇:
https://codeforgeek.com/2014/12/google- ... -tutorial/

先到 google recaptcha 申請:
https://www.google.com/recaptcha/

會取得 Site Key 與 Secret , 將取得的 Site Key 放到表單頁如下:

代碼: 選擇全部

<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="[Site Key]"></div>
Server Side 程式需要對 google 發起 post 到

https://www.google.com/recaptcha/api/siteverify

內容包含:
secret / response (由表單頁帶來的 g-recaptcha-response) / remoteip

回應為 JSON

代碼: 選擇全部

{
  "success": true|false,
  "challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
  "hostname": string,         // the hostname of the site where the reCAPTCHA was solved
  "error-codes": [...]        // optional
}
測試網頁: http://sample.diary.tw/41/google-recaptcha-test.htm
多多留言, 整理文章, 把經驗累積下來.....
回覆文章