Login   Register  
PHP Classes
elePHPant
Icontem

File: RainCaptcha.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of George  >  RainCaptcha  >  RainCaptcha.class.php  >  Download  
File: RainCaptcha.class.php
Role: Class source
Content type: text/plain
Description: RainCaptcha PHP Module
Class: RainCaptcha
Validate CAPTCHA images with RainCaptcha
Author: By
Last change:
Date: 2013-02-19 18:42
Size: 940 bytes
 

Contents

Class file image Download
<?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(100000999999);
        }
        
        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;
        }
    }