pub = $pub; $this->priv = $priv; $this->userclass = explode("|", $userclass); MTrackCaptcha::register($this); } function emit($form) { $class = MTrackAuth::getUserClass(); if (!in_array($class, $this->userclass)) { return ''; } $pub = $this->pub; $err = $this->errcode === null ? '' : "&error=$this->errcode"; return << HTML; } function check($form) { $class = MTrackAuth::getUserClass(); if (!in_array($class, $this->userclass)) { return true; } if (empty($_POST['recaptcha_challenge_field']) or empty($_POST['recaptcha_response_field'])) { return array('false', 'incorrect-captcha-sol'); } $data = http_build_query(array( 'privatekey' => $this->priv, 'remoteip' => $_SERVER['REMOTE_ADDR'], 'challenge' => $_POST['recaptcha_challenge_field'], 'response' => $_POST['recaptcha_response_field'], )); $params = array( 'http' => array( 'method' => 'POST', 'content' => $data, ), ); $ctx = stream_context_create($params); /* first line: true/false * second line: error code */ $res = array(); foreach (file('http://api-verify.recaptcha.net/verify', 0, $ctx) as $line) { $res[] = trim($line); } if ($res[0] == 'true') { return true; } $this->errcode = $res[1]; return false; } }