<?php
/*
** RainCaptcha PHP Wrapper
**
** Documentation: http://raincaptcha.driversworld.us/page/?page=docs_php_wrapper
**
** This code is in the public domain.
*/
class RainCaptcha {
const HOST = 'http://raincaptcha.driversworld.us';
const CODE_LENGTH = 5;
private $key;
public function __construct($key = null) {
if($key === null)
$this->key = md5($_SERVER['SERVER_NAME'] . ':' . $_SERVER['REMOTE_ADDR']);
else
$this->key = $key;
}
public function getImage() {
return self::HOST . '/captcha/?key=' . $this->key . '&random' . rand(100000, 999999);
}
public function checkAnswer($code) {
if(empty($code) || strlen($code) != self::CODE_LENGTH)
return false;
$apiResponse = @file_get_contents(self::HOST . '/captcha/test/?key=' . $this->key . '&code=' . $code);
if($apiResponse == 'true')
return true;
else
return false;
}
}
|