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

From: Date: Sun, 27 Nov 2005 21:19:19 +0000
Subject: cvs: peardoc /en/package text.xml /en/package/text/text-captcha example.xml information.xml intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-7212@lists.php.net to get a copy of this message
mj Sun Nov 27 16:19:19 2005 EDT Added files: /peardoc/en/package/text/text-captcha example.xml information.xml intro.xml Modified files: /peardoc/en/package text.xml Log: * Documentation for Text_CAPTCHA # Written by Christian Wenz. http://cvs.php.net/diff.php/peardoc/en/package/text.xml?r1=1.6&r2=1.7&ty=u Index: peardoc/en/package/text.xml diff -u peardoc/en/package/text.xml:1.6 peardoc/en/package/text.xml:1.7 --- peardoc/en/package/text.xml:1.6 Fri Jul 1 17:51:51 2005 +++ peardoc/en/package/text.xml Sun Nov 27 16:19:18 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <chapter id="package.text"> <title>Text</title> <titleabbrev>Text</titleabbrev> @@ -12,6 +12,7 @@ <simpara /> </sect1> + &package.text.text-captcha; &package.text.text-password; &package.text.text-statistics; &package.text.text-wiki; http://cvs.php.net/co.php/peardoc/en/package/text/text-captcha/example.xml?r=1.1&p=1 Index: peardoc/en/package/text/text-captcha/example.xml +++ peardoc/en/package/text/text-captcha/example.xml <!-- $Revision: 1.1 $ --> <sect2 id="package.text.text-captcha.example"> <title>Example</title> <para> The following example implements the standard use of a CAPTCHA: Submitted form data is only evaluated when a CAPTCHA has been solved correctly. </para> <example id="package.text.text-captcha.example.create"> <title>Creating a CAPTCHA</title> <para> The following code creates a CAPTCHA, provides the relevant information for the package, anhd retrieves the CAPTCHA as a PNG image. </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); </programlisting> </example> <example id="package.text.text-captcha.example.secure"> <title>Securing a form with a 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. </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']); } else { $msg = 'Please try again!'; } unlink(md5(session_id()) . '.png'); } print "<p>$msg</p>"; if (!$ok) { // create the CAPTCHA as seen above // and send it to the client } ]]> </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> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/text/text-captcha/information.xml?r=1.1&p=1 Index: peardoc/en/package/text/text-captcha/information.xml +++ peardoc/en/package/text/text-captcha/information.xml <!-- $Revision: 1.1 $ --> <sect2 id="package.text.text-captcha.information"> <title>Information about the CAPTCHA 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. </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>. </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. </simpara> </listitem> </itemizedlist> </sect2> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/text/text-captcha/intro.xml?r=1.1&p=1 Index: peardoc/en/package/text/text-captcha/intro.xml +++ peardoc/en/package/text/text-captcha/intro.xml <!-- $Revision: 1.1 $ --> <sect2 id="package.text.text-captcha.intro"> <title>Introduction</title> <para> This package provides the functionality to create <acronym>CAPTCHAs</acronym> (Completely Automated Public Turing tests to tell Computers and Humans Apart). Features include: </para> <itemizedlist> <listitem> <simpara> Creating graphical CAPTCHAs using GD2 </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> </simpara> </listitem> </itemizedlist> <para> The package creates <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> 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. </para> </sect2> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->

« previous php.pear.doc (#7212) next »