PHP Classes

File: pic.php

Recommend this page to a friend!
  Classes of xStream   JSCaptcha (unvulnerable anti-bot)   pic.php   Download  
File: pic.php
Role: Auxiliary script
Content type: text/plain
Description: script to draw backend part of captcha
Class: JSCaptcha (unvulnerable anti-bot)
CAPTCHA validation using an image and JavaScript
Author: By
Last change:
Date: 17 years ago
Size: 1,443 bytes
 

Contents

Class file image Download
<?php
error_reporting
(0);
session_start();
$arr=$_SESSION['captcha'][$_GET['session']];
$img=imagecreatetruecolor(112,48);
imagefill($img,0,0,0xFFFFFF);

for(
$i=0;$i<count($arr);$i++)
{
   
$color=0;
   
ereg ("jg.drawLine\(([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+)\);\n", $arr[$i], $regs);
   
$x1=$regs[1]+1;
   
$y1=$regs[2]+1;
   
$x2=$regs[3]+1;
   
$y2=$regs[4]+1;
   
imagelinethick($img, $x1, $y1, $x2, $y2, $color, 4);
}


function
imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
{
    if (
$thick == 1) {
        return
imageline($image, $x1, $y1, $x2, $y2, $color);
    }
   
$t = $thick/2- 0.5;
    if (
$x1 == $x2 || $y1 == $y2) {
        return
imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
    }
   
$dx=($x2 - $x1) / sqrt(($x2 - $x1)*($x2 - $x1));
   
$dy=($y2 - $y1) / sqrt(($y2 - $y1)*($y2 - $y1));
   
$points = array(
       
round($x1 - $t*$dx), round($y1 + $t*$dy),
       
round($x1 - $t*$dx), round($y1 - $t*$dy),
       
round($x1 + $t*$dx), round($y1 - $t*$dy),

       
round($x2 + $t*$dx), round($y2 - $t*$dy),
       
round($x2 + $t*$dx), round($y2 + $t*$dy),
       
round($x2 - $t*$dx), round($y2 + $t*$dy)
    );
   
imagefilledpolygon($image, $points, 6, $color);
    return
imagepolygon($image, $points, 6, $color);
}

header('Content-type: image/gif');
imagegif($img);
imagedestroy($img);
?>