Zend_Service-ReCaptcha.xml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.recaptcha">
  4. <title>Zend_Service_ReCaptcha</title>
  5. <sect2 id="zend.service.recaptcha.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_ReCaptcha</classname> provides a client for the <ulink
  9. url="http://recaptcha.net/">reCAPTCHA Web Service</ulink>.
  10. Per the reCAPTCHA site, "reCAPTCHA is a free CAPTCHA service that
  11. helps to digitize books." Each reCAPTCHA requires the user to input
  12. two words, the first of which is the actual captcha, and the second
  13. of which is a word from some scanned text that Optical Character
  14. Recognition (OCR) software has been unable to identify.
  15. The assumption is that if a user correctly provides the first
  16. word, the second is likely correctly entered as well, and can be
  17. used to improve OCR software for digitizing books.
  18. </para>
  19. <para>
  20. In order to use the reCAPTCHA service, you will need to <ulink
  21. url="http://recaptcha.net/whyrecaptcha.html">sign up for an
  22. account</ulink> and register one or more domains with the
  23. service in order to generate public and private keys.
  24. </para>
  25. </sect2>
  26. <sect2 id="zend.service.recaptcha.simplestuse">
  27. <title>Simplest use</title>
  28. <para>
  29. Instantiate a <classname>Zend_Service_ReCaptcha</classname> object, passing it
  30. your public and private keys:
  31. </para>
  32. <programlisting language="php"><![CDATA[
  33. $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
  34. ]]></programlisting>
  35. <para>
  36. To render the reCAPTCHA, simply call the <code>getHTML()</code>
  37. method:
  38. </para>
  39. <programlisting language="php"><![CDATA[
  40. echo $recaptcha->getHTML();
  41. ]]></programlisting>
  42. <para>
  43. When the form is submitted, you should receive two fields,
  44. 'recaptcha_challenge_field' and 'recaptcha_response_field'. Pass
  45. these to the ReCaptcha object's <code>verify()</code> method:
  46. </para>
  47. <programlisting language="php"><![CDATA[
  48. $result = $recaptcha->verify(
  49. $_POST['recaptcha_challenge_field'],
  50. $_POST['recaptcha_response_field']
  51. );
  52. ]]></programlisting>
  53. <para>
  54. Once you have the result, test against it to see if it is valid. The
  55. result is a <classname>Zend_Service_ReCaptcha_Response</classname> object,
  56. which provides an <code>isValid()</code> method.
  57. </para>
  58. <programlisting language="php"><![CDATA[
  59. if (!$result->isValid()) {
  60. // Failed validation
  61. }
  62. ]]></programlisting>
  63. <para>
  64. Even simpler is to use <link
  65. linkend="zend.captcha.adapters.recaptcha">the ReCaptcha</link>
  66. <classname>Zend_Captcha</classname> adapter, or to use that adapter as a
  67. backend for the <link
  68. linkend="zend.form.standardElements.captcha">Captcha form
  69. element</link>. In each case, the details of rendering and
  70. validating the reCAPTCHA are automated for you.
  71. </para>
  72. </sect2>
  73. </sect1>
  74. <!--
  75. vim:se ts=4 sw=4 et:
  76. -->