【伍哥原创】
什么是Google recaptcha?
简单来说就是一个生成验证码的web service。
详情可以参看 http://www.google.com/recaptcha 。
使用前准备:
使用Google recaptcha之前,需要先申请API key。
首先打开这个页面 http://www.google.com/recaptcha/whyrecaptcha,看到红色“sign up now”按钮,猛击之。
先登陆google account,然后会跳转到注册页,请填一个域名,最好勾选“global key”这个复选框,确定并提交。
接着你就能看到API keys了:
Domain Name: global-key.xxxxx.com
This is a global key. It will work across all domains.
Public Key: 6LflatISAAAAAAn2fBhQ6lVsxA3AN8xzGzSz-OgV
Use this in the JavaScript code that is served to your users
Private Key: 6LflatISAAAAAAUPgQHUp8hcR-3sq1_p56VtU86U
Use this when communicating between your server and our server. Be sure to keep it a secret.
... ...
由上面可以看到有公钥和私钥之分,这两个东东怎么用,呵呵,下面马上告诉你。
如何在PHP中应用Google recaptcha?
下面的文档说得太详细了,以至于我都不想在这里重复,直接贴链接吧。英文非常的简单,代码也有了,不要跟我说在PHP里不会用哦!
https://developers.google.com/recaptcha/docs/php
下载PHP lib包:http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest
显示验证码的页面(index.php,记得加上公钥)
成功页面(verify.php,记得加上私钥)
失败页面(verify.php)