Bontiv-Sourceer source code viewer
Root | Help
./PhpMyCMS/captcha.php
<?php

/**
 * captcha générator
 *
 * @version $Id$
 * @copyright 2009
 */

define('X_SIZE', 150);
define('Y_SIZE', 60);

include_once
'config.php';
include_once
"inc/session.php";

function
is_font($font){
    return (
strrchr(strtolower($font), '.') == '.ttf')?(TRUE):(FALSE);
}

$key = md5(uniqid());
$key = substr($key, rand(0, 20), 5);
$key = strtoupper($key);
$key = str_replace('O', '0', $key);
$session = session::Open();
session::SetVar('captcha', $key);
$session->RecVar();

$font = scandir('font');
$font = array_filter($font, 'is_font');

$im = imagecreate(X_SIZE, Y_SIZE);
imagefill($im, 0, 0, imagecolorallocate($im, 250, 250, 200));

$MyXpos = 10;
for (
$pos = 0; $pos < 5; $pos++){
   
$MyFont = 'font/'.$font[array_rand($font)];
   
$MyColor = imagecolorallocate($im, rand(0,100), rand(0,100), rand(0,100));
   
$MyAngle = rand(-40, 40);
   
$MyText = substr($key, $pos, 1);
   
$MyDim = imagettfbbox(16, $MyAngle, $MyFont, $MyText);
   
$MyXpos = $pos*X_SIZE/5+5;
   
$MyYpos = 20;
   
imagettftext($im, 20, $MyAngle, $MyXpos, 35, $MyColor, $MyFont, $MyText);
}

for (
$i = 0; $i < 200; $i++){
   
$MyColor = imagecolorallocate($im, rand(100,255), rand(100,255), rand(100,255));
   
$MyXlen = rand(0,10);
   
$MyYlen = rand(-10,10);
   
$MyXpos = rand(0, X_SIZE - $MyXlen);
   
$MyYpos = rand(0, Y_SIZE - $MyYlen);
   
imageline($im, $MyXpos, $MyYpos, $MyXpos+$MyXlen, $MyYpos+$MyYlen, $MyColor);
}


header('Content-type: image/png');
imagepng($im);
?>
Presented with Bontiv-Sourceer