1 |
624
|
thorn
|
<?php
|
2 |
|
|
|
3 |
|
|
// $Id$
|
4 |
|
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9 |
|
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Must include code to stop this file being accessed directly
|
27 |
|
|
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
|
28 |
|
|
|
29 |
|
|
$name = 'text';
|
30 |
|
|
$file = WB_PATH."/temp/.captcha_$name.txt";
|
31 |
|
|
|
32 |
|
|
srand((double)microtime()*100000);
|
33 |
|
|
$_SESSION['captcha'] = rand(0,99999);
|
34 |
|
|
|
35 |
|
|
// get questions and answers
|
36 |
|
|
$qa = array();
|
37 |
|
|
@$content = file($file);
|
38 |
|
|
if($content===FALSE) {
|
39 |
|
|
echo '<b>Error</b>: Can not read text! Enter <b>0</b> to solve this captcha';
|
40 |
|
|
$_SESSION['captcha'] = '0';
|
41 |
|
|
exit;
|
42 |
|
|
}
|
43 |
|
|
reset($content);
|
44 |
|
|
while($s = current($content)) {
|
45 |
|
|
// get question
|
46 |
|
|
$s=trim(rtrim(rtrim($s,"\n"),"\r")); // remove newline
|
47 |
|
|
if($s=='' OR $s{0}!='?') {
|
48 |
|
|
next($content);
|
49 |
|
|
continue;
|
50 |
|
|
}
|
51 |
|
|
if(isset($s{3}) && $s{3}==':') {
|
52 |
|
|
$lang=substr($s,1,2);
|
53 |
|
|
$q=substr($s,4);
|
54 |
|
|
} else {
|
55 |
|
|
$lang='XX';
|
56 |
|
|
$q=substr($s,1);
|
57 |
|
|
}
|
58 |
|
|
// get answer
|
59 |
|
|
$s=next($content);
|
60 |
|
|
$s=trim(rtrim(rtrim($s,"\n"),"\r")); // remove newline
|
61 |
625
|
thorn
|
if(isset($s{0}) && $s{0}!='!') continue;
|
62 |
624
|
thorn
|
$a=substr($s,1);
|
63 |
|
|
$qa[$lang][$q]=$a;
|
64 |
|
|
next($content);
|
65 |
|
|
}
|
66 |
|
|
if($qa == array()) {
|
67 |
|
|
echo '<b>Error</b>: no text defined! Enter <b>0</b> to solve this captcha';
|
68 |
|
|
$_SESSION['captcha'] = '0';
|
69 |
|
|
exit;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
// choose language to use
|
73 |
|
|
if(defined('LANGUAGE') && isset($qa[LANGUAGE]))
|
74 |
|
|
$lang = LANGUAGE;
|
75 |
|
|
else
|
76 |
|
|
$lang = 'XX';
|
77 |
|
|
if(!isset($qa[$lang])) {
|
78 |
|
|
echo '<b>Error</b>: no text defined! Enter <b>0</b> to solve this captcha';
|
79 |
|
|
$_SESSION['captcha'] = '0';
|
80 |
|
|
exit;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
// choose random question
|
84 |
|
|
$k = array_rand($qa[$lang]);
|
85 |
|
|
|
86 |
|
|
$_SESSION['captcha'] = $qa[$lang][$k];
|
87 |
|
|
|
88 |
|
|
echo $k;
|
89 |
|
|
|
90 |
625
|
thorn
|
?>
|