Blame | Letzte Änderung | Log anzeigen | RSS feed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1"><LINK REL="Start" HREF="index.html"><LINK REL="Contents" HREF="toc.html"><LINK REL="Prev" HREF="11AntiSpamChallenges.html"><LINK REL="Next" HREF="12CodedefinesinJpGraph.html"><STYLE TYPE="text/css"><!--BODY { font-family: serif }H1 { font-family: sans-serif }H2 { font-family: sans-serif }H3 { font-family: sans-serif }H4 { font-family: sans-serif }H5 { font-family: sans-serif }H6 { font-family: sans-serif }SUB { font-size: smaller }SUP { font-size: smaller }PRE { font-family: monospace }A { text-decoration: none }--></STYLE></HEAD><BODY><A HREF="toc.html">Contents</A><A HREF="11AntiSpamChallenges.html">Previous</A><A HREF="12CodedefinesinJpGraph.html">Next</A><HR NOSHADE><H2><A NAME="11_1">11.1 Generating Anti-Spam challenge</A></H2><P> There are two basic alternatives on how to generate the content ofthe anti-spam image</P><OL><LI> Submit a string that should be used</LI><LI> Automatically generate a random string. If this alternative ischosen then the user of the library should save the created string andcompare it to what the user enters.</LI></OL><P> In order to write a script to generate a new challenge there arefour steps to be completed.</P><P><B> First</B> include the library file<I> jpgraph_antispam.php</I>.Note that there is no need to include the "jpgraph.php" library sinceall functionality is included in this library file.<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#007700">require_once </FONT><FONT color="#DD0000">"jpgraph_antispam.php"</FONT><FONTcolor="#007700">;</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P><B> Secondly</B> a new instance of the class<I> AntiSpam</I> must becreated<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> $spam </FONT><FONT color="#007700">= new </FONT><FONT color="#0000BB">AntiSpam</FONT><FONT color="#007700">();</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P><B> Thirdly</B> the string to be used in the challenge must bespecified. To automatically generate a suitable string use<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#FF8000">// The argument determines the length of the generated string<BR></FONT><FONT color="#0000BB">$chars </FONT><FONT color="#007700">= </FONT><FONTcolor="#0000BB">$spam</FONT><FONT color="#007700">-></FONT><FONT color="#0000BB">Rand</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">5</FONT><FONTcolor="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P> If instead the string to be used should be specified this stringshould be specified in the initial creation of the AntiSpam() or bycalling the<I> Set()</I> method as in<DIV class="phpscript"><CODE><FONT color="#000000"><FONT color="#0000BB"> $spam</FONT><FONT color="#007700">-></FONT><FONT color="#0000BB">Set</FONT><FONT color="#007700">(</FONT><FONT color="#DD0000">"aui8k"</FONT><FONTcolor="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P>Please note that in order to minimize the risk for confusion theletters 'O' and the number '0' (zero) is not allowed since they are tooalike and can be mistaken for each other.</P><P><B> The final and fourth step</B> is to output the image with a callthe method<I> Stroke()</I> on the created instance of the<I> AntiSpam</I>class.<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#007700">if( </FONT><FONT color="#0000BB">$spam</FONT><FONTcolor="#007700">-></FONT><FONT color="#0000BB">Stroke</FONT><FONT color="#007700">() === </FONT><FONT color="#0000BB">false </FONT><FONT color="#007700">) {<BR> die(</FONT><FONT color="#DD0000">"Illegal or no data to plot"</FONT><FONTcolor="#007700">);<BR>}</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P>Note that we have put a guard around the output since in the case ofan error this method will result a boolean false value. As with theother graph types it is possible to write the generated image to a fileby submitting a file name as an argument to<I> Stroke()</I>.</P><HR NOSHADE><A HREF="toc.html">Contents</A><A HREF="11AntiSpamChallenges.html">Previous</A><A HREF="12CodedefinesinJpGraph.html">Next</A></BODY></HTML>