cvs: peardoc /en/package/text/text-captcha example.xml information.xml intro.xml

From: Date: Sun, 26 Nov 2006 17:24:20 +0000
Subject: cvs: peardoc /en/package/text/text-captcha example.xml information.xml intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-8905@lists.php.net to get a copy of this message
davidc Sun Nov 26 17:24:20 2006 UTC Modified files: /peardoc/en/package/text/text-captcha example.xml information.xml intro.xml Log: - Made the docbook documentation for the text-captcha-numeral package

http://cvs.php.net/viewvc.cgi/peardoc/en/package/text/text-captcha/example.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/text/text-captcha/example.xml diff -u peardoc/en/package/text/text-captcha/example.xml:1.1 peardoc/en/package/text/text-captcha/example.xml:1.2 --- peardoc/en/package/text/text-captcha/example.xml:1.1 Sun Nov 27 21:19:19 2005 +++ peardoc/en/package/text/text-captcha/example.xml Sun Nov 26 17:24:20 2006 @@ -1,5 +1,5 @@ -<!-- $Revision: 1.1 $ --> -<sect2 id="package.text.text-captcha.example"> +<!-- $Id: example.xml,v 1.2 2006/11/26 17:24:20 davidc Exp $ --> +<sect2 id="package.text.text-captcha-numeral.example"> <title>Example</title> <para> @@ -8,86 +8,71 @@ solved correctly. </para> - <example id="package.text.text-captcha.example.create"> - <title>Creating a CAPTCHA</title> + <example id="package.text.text-captcha-numeral.example.create"> + <title>Creating a Numeral CAPTCHA</title> <para> - The following code creates a CAPTCHA, provides the relevant - information for the package, anhd retrieves the CAPTCHA as a - PNG image. + This example is just to show you how to generate a simple mathematic + operation with Text_CAPTCHA_Numeral. </para> <programlisting role="php"> -require_once 'Text/CAPTCHA.php'; - -// Set CAPTCHA options (font must exist!) -$options = array( - 'font_size' => 24, - 'font_path' => './', - 'font_file' => 'COUR.TTF' -); - -// Generate a new Text_CAPTCHA object, Image driver -$c = Text_CAPTCHA::factory('Image'); -$retval = $c->init(200, 80, null, $options); -if (PEAR::isError($retval)) { - echo 'Error generating CAPTCHA!'; - exit; -} - -// Get CAPTCHA secret passphrase -$_SESSION['phrase'] = $c->getPhrase(); - -// Get CAPTCHA image (as PNG) -$png = $c->getCAPTCHAAsPNG(); -if (PEAR::isError($png)) { - echo 'Error generating CAPTCHA!'; - exit; -} -file_put_contents(md5(session_id()) . '.png', $png); +require_once 'Text/CAPTCHA/Numeral.php'; +$num = new Text_CAPTCHA_Numeral; +$operation = $num->getOperation(); + +/** + * This will print the mathematical operation + * that has been generated by the package. + */ +print $operation; </programlisting> </example> - <example id="package.text.text-captcha.example.secure"> - <title>Securing a form with a CAPTCHA</title> + <example id="package.text.text-captcha-numeral.example.secure"> + <title>Securing a form with a Numeral CAPTCHA</title> <para> - The following code implements the functionality to check whether - a CAPTCHA was solved correctly or not. for this, the - CAPTCHA's phrase is stored in a session variable to - retain this information between requests. It is - important to unset the session after solving the - CAPTCHA to avoid the reuse of the session ID. + This example will show you how to secure a form using the + numeral captcha. It takes generates an operation and store + it's result into a session variable </para> <programlisting role="php"> <![CDATA[ -session_start(); -$ok = false; -$msg = 'Please enter the text in the image in the field below!'; -if ($_SERVER['REQUEST_METHOD'] == 'POST') { - if (isset($_POST['phrase']) && isset($_SESSION['phrase']) && - strlen($_POST['phrase']) > 0 && strlen($_SESSION['phrase']) > 0 && - $_POST['phrase'] == $_SESSION['phrase']) { - $msg = 'OK!'; - $ok = true; - unset($_SESSION['phrase']); +require_once 'Text/CAPTCHA/Numeral.php'; +$numcap = new Text_CAPTCHA_Numeral; + +if (isset($_POST['captcha']) && isset($_SESSION['answer'])) { + if ($_POST['captcha'] == $_SESSION['answer']) { + $errors[] = 'Ok.. YOu might be human..'; } else { - $msg = 'Please try again!'; + $errors[] = 'You are or not human or dumb'; } - unlink(md5(session_id()) . '.png'); } -print "<p>$msg</p>"; + if (!empty($errors)) { + foreach ($errors as $error) { + print "<h1><font color='red'>$error</font></h1><br />"; + } + } -if (!$ok) { - // create the CAPTCHA as seen above - // and send it to the client -} + + print ' + <form name="capter" action="index.php?page=liveExample" method="post"> + <table> + <tr> + <th>What is this result pilgrim?: '.$numcap->getOperation().'</th> + <td><input type="text" value="" name="captcha" /></td> + </tr> + <tr> + <th/> + <td><input type="submit" value="Let me prove you that I am human!" /></td> + </tr> + </form> + '; + $_SESSION['answer'] = $numcap->getAnswer(); ]]> </programlisting> - <para>See the file <filename>CAPTCHA_test.php</filename> - in the package distribution for a full, working - example (GD and TTF support required).</para> </example> </sect2> http://cvs.php.net/viewvc.cgi/peardoc/en/package/text/text-captcha/information.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/text/text-captcha/information.xml diff -u peardoc/en/package/text/text-captcha/information.xml:1.1 peardoc/en/package/text/text-captcha/information.xml:1.2 --- peardoc/en/package/text/text-captcha/information.xml:1.1 Sun Nov 27 21:19:19 2005 +++ peardoc/en/package/text/text-captcha/information.xml Sun Nov 26 17:24:20 2006 @@ -1,46 +1,24 @@ -<!-- $Revision: 1.1 $ --> -<sect2 id="package.text.text-captcha.information"> - <title>Information about the CAPTCHA and inner workings</title> +<!-- $Id: information.xml,v 1.2 2006/11/26 17:24:20 davidc Exp $ --> +<sect2 id="package.text.text-captcha-numeral.information"> + <title>Information about the Text_CAPTCHA_Numeral and inner workings</title> <para> - <classname>Text_CAPTCHA</classname> provides information - about the CAPTCHA and makes its inner workings accessible - using several functions defined in the base - class; the specific implementation of them is up to - the driver. + <classname>Text_CAPTCHA_Numeral</classname> gives you the ability + to generate numerical mathematical captchas. </para> <itemizedlist> <listitem> <simpara> - <function>init</function> is used to initialize the CAPTCHA and provide - further information, like <classname>Image_Text</classname> - parameters. - </simpara> - </listitem> - <listitem> - <simpara> - <function>_createCAPTCHA</function> generates the CAPTCHA, but is called - internally by <function>init</function>. + <function>getOperation</function> generates the operation + that is going to be shown to the end user. </simpara> <simpara> - <function>getPhrase</function> returns the CAPTCHA's phrase. - </simpara> - </listitem> - <listitem> - <simpara> - <function>_createPhrase</function> creates a phrase for the CAPTCHA, - but is used internally. - </simpara> - </listitem> - <listitem> - <simpara> - <function>getCAPTCHA</function> returns the CAPTCHA, the format used - depends on the driver implementation. + <function>getAnswer</function> Gets the answer of the generated + operation's answer. </simpara> </listitem> </itemizedlist> - </sect2> <!-- Keep this comment at the end of the file http://cvs.php.net/viewvc.cgi/peardoc/en/package/text/text-captcha/intro.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/text/text-captcha/intro.xml diff -u peardoc/en/package/text/text-captcha/intro.xml:1.1 peardoc/en/package/text/text-captcha/intro.xml:1.2 --- peardoc/en/package/text/text-captcha/intro.xml:1.1 Sun Nov 27 21:19:19 2005 +++ peardoc/en/package/text/text-captcha/intro.xml Sun Nov 26 17:24:20 2006 @@ -1,9 +1,9 @@ -<!-- $Revision: 1.1 $ --> -<sect2 id="package.text.text-captcha.intro"> +<!-- $Id: intro.xml,v 1.2 2006/11/26 17:24:20 davidc Exp $ --> +<sect2 id="package.text.text-captcha-numeral.intro"> <title>Introduction</title> <para> - This package provides the functionality to create + This package provides the functionality to create Numeral <acronym>CAPTCHAs</acronym> (Completely Automated Public Turing tests to tell Computers and Humans Apart). Features include: </para> @@ -11,33 +11,27 @@ <itemizedlist> <listitem> <simpara> - Creating graphical CAPTCHAs using GD2 + Creating numerical Captchas </simpara> </listitem> <listitem> <simpara> - Pluggable driver architecture using factory pattern - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="package.text.text-captcha.information"> - Generic information about the CAPTCHA + <link linkend="package.text.text-captcha-numeral.information"> + Generic information about the Text_CAPTCHA_Numeral </link> </simpara> </listitem> </itemizedlist> <para> - The package creates <acronym>CAPTCHAs</acronym>; due to the + The package creates numeral <acronym>CAPTCHAs</acronym>; due to the stateless nature of the HTTP protocol, the logic to secure a webpage using the package must be specifically implemented. - See the <link linkend="package.text.text-captcha.example">usage example</link> + See the <link linkend="package.text.text-captcha-numeral.example">usage example</link> for detailled information. </para> <para> - Currently, the graphical CAPTCHA driver depends on Image_Text which in turn - requires TTF support to be compiled into PHP. + Currently </para> </sect2>
« previous php.pear.doc (#8905) next »