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 ~~  >  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: Version 1.1.0
Date: 1 year ago
Size: 911 bytes
 

Contents

Class file image Download
<?php
    
/* 
    ** RainCaptcha PHP Wrapper v1.1.0
    **
    ** Documentation: http://raincaptcha.driversworld.us/pages/docs_php_wrapper
    **
    ** This code is in the public domain.
    */
    
    
class RainCaptcha {
        const 
HOST 'http://raincaptcha.driversworld.us/api/v1';
        
        private 
$sessionId;
        
        public function 
__construct($sessionId null) {
            if(
$sessionId === null)
                
$this->sessionId md5($_SERVER['SERVER_NAME'] . ':' $_SERVER['REMOTE_ADDR']);
            else
                
$this->sessionId $sessionId;
        }
        
        public function 
getImage() {
            return 
self::HOST '/image/' $this->sessionId '?rand' rand(100000999999);
        }
        
        public function 
checkAnswer($answer) {
            if(empty(
$answer))
                return 
false;
            
$response = @file_get_contents(self::HOST '/check/' $this->sessionId'/' $answer);
            if(
$response === false)
                return 
true;
            return 
$response === 'true';
        }
    }