Login   Register  
PHP Classes
elePHPant
Icontem

File: asf_gencode.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Dmitry Sheiko  >  AntiSpam Feedback  >  asf_gencode.php  >  Download  
File: asf_gencode.php
Role: Auxiliary script
Content type: text/plain
Description: graphical code generator
Class: AntiSpam Feedback
Verify the e-mail of users sending feedback forms
Author: By
Last change: CAPTHA improved
Date: 2008-06-12 08:59
Size: 1,754 bytes
 

Contents

Class file image Download
<?PHP
/*
* Confirmation Code Generator
*
* @package Confirmation Code Generator
* @author $Author: sheiko $  
* @version $Id: gencode.php, v 1.0 sheiko Exp $ 
* @since v.1.0 
* @copyright (c) Dmitry Sheiko http://www.cmsdevelopment.com 
*/ 

srand(round(microtime(1)*10000));

/** 
* Get confirmation code

* @return sting
*/         
function gen_key($string){
    
$im=imagecreatetruecolor(strlen($string)*22.525);
    
imagetruecolortopalette($im1256);
    
$white=imagecolorallocate($im221194164);

    
imagefill($im00$white);

    
$x=0;
    for (
$i=0$i<strlen($string); $i++){
        
$tmp=imagecreatetruecolor(2020);
        
$tbg=imagecolorallocate($tmp221194164);

        
imagefill($tmp00$tbg);

        
$color=imagecolorallocate($tmprand(5150), rand(5100), rand(5100));
        
imagechar($tmp522$string[$i], $color);
        
$tmp=imagerotate($tmprand(-4040), $tbg);
        
imagecopy($im$tmp$x111imagesx($tmp)-1imagesy($tmp)-1);
        
$x+=imagesx($tmp)-7;
        
imagedestroy($tmp);
    }
    
imagecolortransparent($im$white);
    
$x+=8;
    
$out=imagecreatetruecolor(strlen($string)*22.5*1.545);

    
$background=imagecreatefromjpeg(dirname(__FILE__) . "/asf_gencode.jpg");
    
imagecopyresampled($out$background0000imagesx($out), imagesy($out), imagesx($background), imagesy($background));
    
imagedestroy($background);

    
imagecopyresampled($out$im0000strlen($string)*22.5*1.545$x25);
    
imagedestroy($im);
    
header("Content-Type: image/png");
    
imagetruecolortopalette($out0256);
    
imagepng($out);
    
imagedestroy($out);
}
session_start("asf"); 
$string substr(md5(rand(1,100)),0,5);
$_SESSION["Md5OfGenCode"] = md5($string);
if(!
$string$string "ERROR";
gen_key($string);
?>