PHP Classes

File: asf_gencode.php

Recommend this page to a friend!
  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: 16 years ago
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.5, 25);
   
imagetruecolortopalette($im, 1, 256);
   
$white=imagecolorallocate($im, 221, 194, 164);

   
imagefill($im, 0, 0, $white);

   
$x=0;
    for (
$i=0; $i<strlen($string); $i++){
       
$tmp=imagecreatetruecolor(20, 20);
       
$tbg=imagecolorallocate($tmp, 221, 194, 164);

       
imagefill($tmp, 0, 0, $tbg);

       
$color=imagecolorallocate($tmp, rand(5, 150), rand(5, 100), rand(5, 100));
       
imagechar($tmp, 5, 2, 2, $string[$i], $color);
       
$tmp=imagerotate($tmp, rand(-40, 40), $tbg);
       
imagecopy($im, $tmp, $x, 1, 1, 1, imagesx($tmp)-1, imagesy($tmp)-1);
       
$x+=imagesx($tmp)-7;
       
imagedestroy($tmp);
    }
   
imagecolortransparent($im, $white);
   
$x+=8;
   
$out=imagecreatetruecolor(strlen($string)*22.5*1.5, 45);

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

   
imagecopyresampled($out, $im, 0, 0, 0, 0, strlen($string)*22.5*1.5, 45, $x, 25);
   
imagedestroy($im);
   
header("Content-Type: image/png");
   
imagetruecolortopalette($out, 0, 256);
   
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);
?>