php Google reCAPTCHA2.0範例

php Google reCAPTCHA2.0範例(查看次數:922)

回首頁

2015-06-02 22:38:22

申請Google reCAPTCHA2.0要如何應用在自己的網站,底下用php當範例,說明要如何將Site key是前端用跟後端Secret key的應用,請將這二組換成您自己申請的網域或ip。


測試網網: http://bestdaylong.com/html/recaptcha.htm


google_recaptcha_04
1.登入太多次會出現圖片選取


google_recaptcha_05
2.或是輸入文字


google_recaptcha_06
3.勾選【我不是機器人】按下【Submit】


google_recaptcha_07
4.php程式碼


google_recaptcha_08
5.認證成功


google_recaptcha_09
6.前端在<form>跟</form>加上Site key


recaptcha.php




[code]
<?php
$secret_key = '6LcNvAcTAAAAAJT4S5bdub0uIeV8_1reBUygYXDD';
$g_recaptcha_response=$_POST['g-recaptcha-response'];
$remoteip=$_SERVER['REMOTE_ADDR'];
$url ="https://www.google.com/recaptcha/api/siteverify?secret={$secret_key}&response={$g_recaptcha_response}&remoteip={$remoteip}";
$web=file_get_contents($url);
$res = json_decode($web);

if($res->success)
echo "success";
else
echo "fail";
?>[/code]

 

php Google reCAPTCHA2.0範例
上一篇:ipad2 如何下載youtube(2023)      下一篇:wc_admin_unsnooze_admin_notes(0)