| 1 |
lars |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
|
|
|
5 |
<LINK REL="Start" HREF="index.html">
|
|
|
6 |
<LINK REL="Contents" HREF="toc.html">
|
|
|
7 |
<LINK REL="Prev" HREF="11AntiSpamChallenges.html">
|
|
|
8 |
<LINK REL="Next" HREF="12CodedefinesinJpGraph.html">
|
|
|
9 |
<STYLE TYPE="text/css"><!--
|
|
|
10 |
BODY { font-family: serif }
|
|
|
11 |
H1 { font-family: sans-serif }
|
|
|
12 |
H2 { font-family: sans-serif }
|
|
|
13 |
H3 { font-family: sans-serif }
|
|
|
14 |
H4 { font-family: sans-serif }
|
|
|
15 |
H5 { font-family: sans-serif }
|
|
|
16 |
H6 { font-family: sans-serif }
|
|
|
17 |
SUB { font-size: smaller }
|
|
|
18 |
SUP { font-size: smaller }
|
|
|
19 |
PRE { font-family: monospace }
|
|
|
20 |
A { text-decoration: none }
|
|
|
21 |
--></STYLE>
|
|
|
22 |
</HEAD>
|
|
|
23 |
<BODY>
|
|
|
24 |
<A HREF="toc.html">Contents</A>
|
|
|
25 |
<A HREF="11AntiSpamChallenges.html">Previous</A>
|
|
|
26 |
<A HREF="12CodedefinesinJpGraph.html">Next</A>
|
|
|
27 |
<HR NOSHADE>
|
|
|
28 |
<H2><A NAME="11_1">11.1 Generating Anti-Spam challenge</A></H2>
|
|
|
29 |
<P> There are two basic alternatives on how to generate the content of
|
|
|
30 |
the anti-spam image</P>
|
|
|
31 |
<OL>
|
|
|
32 |
<LI> Submit a string that should be used</LI>
|
|
|
33 |
<LI> Automatically generate a random string. If this alternative is
|
|
|
34 |
chosen then the user of the library should save the created string and
|
|
|
35 |
compare it to what the user enters.</LI>
|
|
|
36 |
</OL>
|
|
|
37 |
<P> In order to write a script to generate a new challenge there are
|
|
|
38 |
four steps to be completed.</P>
|
|
|
39 |
<P><B> First</B> include the library file<I> jpgraph_antispam.php</I>.
|
|
|
40 |
Note that there is no need to include the "jpgraph.php" library since
|
|
|
41 |
all functionality is included in this library file.<DIV class="phpscript">
|
|
|
42 |
<CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#007700">
|
|
|
43 |
require_once </FONT><FONT color="#DD0000">"jpgraph_antispam.php"</FONT><FONT
|
|
|
44 |
color="#007700">;</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV>
|
|
|
45 |
</P>
|
|
|
46 |
<P><B> Secondly</B> a new instance of the class<I> AntiSpam</I> must be
|
|
|
47 |
created<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
|
|
|
48 |
$spam </FONT><FONT color="#007700">= new </FONT><FONT color="#0000BB">
|
|
|
49 |
AntiSpam</FONT><FONT color="#007700">();</FONT><FONT color="#0000BB"></FONT>
|
|
|
50 |
</FONT></CODE></DIV></P>
|
|
|
51 |
<P><B> Thirdly</B> the string to be used in the challenge must be
|
|
|
52 |
specified. To automatically generate a suitable string use<DIV class="phpscript">
|
|
|
53 |
<CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#FF8000">
|
|
|
54 |
// The argument determines the length of the generated string
|
|
|
55 |
<BR></FONT><FONT color="#0000BB">$chars </FONT><FONT color="#007700">= </FONT><FONT
|
|
|
56 |
color="#0000BB">$spam</FONT><FONT color="#007700">-></FONT><FONT color="#0000BB">
|
|
|
57 |
Rand</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">5</FONT><FONT
|
|
|
58 |
color="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV>
|
|
|
59 |
</P>
|
|
|
60 |
<P> If instead the string to be used should be specified this string
|
|
|
61 |
should be specified in the initial creation of the AntiSpam() or by
|
|
|
62 |
calling the<I> Set()</I> method as in<DIV class="phpscript"><CODE><FONT color="#000000">
|
|
|
63 |
<FONT color="#0000BB"> $spam</FONT><FONT color="#007700">-></FONT><FONT color="#0000BB">
|
|
|
64 |
Set</FONT><FONT color="#007700">(</FONT><FONT color="#DD0000">"aui8k"</FONT><FONT
|
|
|
65 |
color="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV>
|
|
|
66 |
</P>
|
|
|
67 |
<P>Please note that in order to minimize the risk for confusion the
|
|
|
68 |
letters 'O' and the number '0' (zero) is not allowed since they are too
|
|
|
69 |
alike and can be mistaken for each other.</P>
|
|
|
70 |
<P><B> The final and fourth step</B> is to output the image with a call
|
|
|
71 |
the method<I> Stroke()</I> on the created instance of the<I> AntiSpam</I>
|
|
|
72 |
class.<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
|
|
|
73 |
</FONT><FONT color="#007700">if( </FONT><FONT color="#0000BB">$spam</FONT><FONT
|
|
|
74 |
color="#007700">-></FONT><FONT color="#0000BB">Stroke</FONT><FONT color="#007700">
|
|
|
75 |
() === </FONT><FONT color="#0000BB">false </FONT><FONT color="#007700">
|
|
|
76 |
) {
|
|
|
77 |
<BR> die(</FONT><FONT color="#DD0000">"Illegal or no data to plot"</FONT><FONT
|
|
|
78 |
color="#007700">);
|
|
|
79 |
<BR>}</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P>
|
|
|
80 |
<P>Note that we have put a guard around the output since in the case of
|
|
|
81 |
an error this method will result a boolean false value. As with the
|
|
|
82 |
other graph types it is possible to write the generated image to a file
|
|
|
83 |
by submitting a file name as an argument to<I> Stroke()</I>.</P>
|
|
|
84 |
<HR NOSHADE>
|
|
|
85 |
<A HREF="toc.html">Contents</A>
|
|
|
86 |
<A HREF="11AntiSpamChallenges.html">Previous</A>
|
|
|
87 |
<A HREF="12CodedefinesinJpGraph.html">Next</A>
|
|
|
88 |
</BODY>
|
|
|
89 |
</HTML>
|