1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
6 class MTrack_Captcha_Recaptcha implements MTrack_Implementation_Captcha
8 public $errcode = null;
13 function __construct($pub, $priv, $userclass = 'anonymous|authenticated') {
16 $this->userclass = explode("|", $userclass);
17 MTrackCaptcha::register($this);
22 $class = MTrackAuth::getUserClass();
23 if (!in_array($class, $this->userclass)) {
27 $err = $this->errcode === null ? '' : "&error=$this->errcode";
29 <script type='text/javascript' src="https://api-secure.recaptcha.net/challenge?k=$pub$err"></script>
31 <iframe src="https://api-secure.recaptcha.net/noscript?k=$pub$err"
32 height="300" width="500" frameborder="0"></iframe>
34 <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
35 <input type="hidden" name="recaptcha_response_field"
36 value="manual_challenge"/>
43 $class = MTrackAuth::getUserClass();
44 if (!in_array($class, $this->userclass)) {
47 if (empty($_POST['recaptcha_challenge_field']) or
48 empty($_POST['recaptcha_response_field'])) {
49 return array('false', 'incorrect-captcha-sol');
52 $data = http_build_query(array(
53 'privatekey' => $this->priv,
54 'remoteip' => $_SERVER['REMOTE_ADDR'],
55 'challenge' => $_POST['recaptcha_challenge_field'],
56 'response' => $_POST['recaptcha_response_field'],
64 $ctx = stream_context_create($params);
66 /* first line: true/false
67 * second line: error code
70 foreach (file('http://api-verify.recaptcha.net/verify', 0, $ctx) as $line) {
73 if ($res[0] == 'true') {
76 $this->errcode = $res[1];