手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2010年01月25日的文章

万能验证码:recaptcha

说是万能,意思是他支持多种程序语言。而且调用方式也非常简单,当然官方也有例子
Recaptcha,这是一个验证码程序,其实真的很方便,如果你一天到晚还在为着验证码被别人破解而不停的改进自己的验证码时,你可以用它;如果你不会写验证码程序,你可以用它;如果你想支持语音验证,你也可以用它;如果你想有更多的功能,当然你一样可以用它。

使用方法比较简单,大致如下:

  1. Download the reCAPTCHA Library, unzip it, and copy recaptchalib.php to the directory where your forms live.先到reCAPTCHA下载PHP类库,解压拷到你的线上目录中
  2. If you haven't done so, sign up for an API key. 准备完后,你可以注册并申请一下API
  3. Now we're ready to start modifying your code. First, we'll add code to display the CAPTCHA:然后,我们开始修改代码。首先,我们先添加显示CAPTCHA验证码的代码 
    PHP代码
    1. require_once('recaptchalib.php');  
    2. $publickey = "..."// you got this from the signup page,这里就是你刚才申请的API KEY 
    3. echo recaptcha_get_html($publickey);  

   4.In the code that processes the form submission, you need to add code to validate the CAPTCHA. Otherwise, the CAPTCHA will appear, but the answers won't be checked. The validation code looks like:在提交处理页,你需要添加CAPTCHA验证代码。否则,CAPTCHA并不会验证他们。验证代码大致如下:

PHP代码
  1. require_once('recaptchalib.php');  
  2. $privatekey = "...";  //申请的API KEY
  3. $resp = recaptcha_check_answer ($privatekey,  
  4.                                 $_SERVER["REMOTE_ADDR"],  
  5.                                 $_POST["recaptcha_challenge_field"],  
  6.                                 $_POST["recaptcha_response_field"]);  
  7.   
  8. if (!$resp->is_valid) {  
  9.   die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .  
  10.        "(reCAPTCHA said: " . $resp->error . ")");  
  11. }  

看起来是不是很简单?现在是不是不再犹豫了??

更多参考和参数可以查看这里:http://recaptcha.net/plugins/php/

 

 

 

Tags: recaptcha