As I mentioned in another post, im working on a little something as an alternative to the generic captcha which looks something like this
PHP Code:
<?php
function RandomStringGenerator($length){
global $string;
$pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
if(empty($length)){
$length = "10";
}
for($i=0; $i<$length; $i++){
$string .= $pattern{rand(0,61)};
}
return $string;
}
function CaptchaGenerator(){
global $string;
RandomStringGenerator();
header("Content-type: image/png");
$im = @imagecreate(100, 50)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 10, 5, 5, $string, $text_color);
imagepng($im);
imagedestroy($im);
}
CaptchaGenerator();
?>
an alternative might be like what color is this shape? or how many sides does this shape have? So I created another random function that creates a random shape a random color at a random size
PHP Code:
<?php
function RandomColorGenerator(){
global $red, $green, $blue, $color;
$color = array(rand(50,255), rand(50,255), rand(50,255)); //generates random RGB color;
$red = $color[1]; //red value;
$green = $color[2]; //green value;
$blue = $color[3]; //blue value;
}
function ShapeGenerator($vertices, $radius) {
global $points;
$points = array();
$degrees = 360/$vertices; //calculates the degrees per angle;
for ($i=0; $i<$vertices; $i++) {
$cos = cos(deg2rad($degrees*$i)); //generates x points;
$sin = sin(deg2rad($degrees*$i)); //generates y points;
$cosTranslated = round($cos*$radius)+$radius; //translates x points;
$sinTranslated = round($sin*$radius)+$radius; //transpates y points;
$points[] = $cosTranslated; //Adds the x and y values to the array;
$points[] .= $sinTranslated; //Adds the x and y values to the array;
}
}
function RandomShape($sides,$radius) {
global $points, $red, $green, $blue;
RandomColorGenerator();
ShapeGenerator($sides, $radius);
$vertices = count($points)/2;
$image = imagecreatetruecolor(400, 400); //creates drawing canvass
$bg = imagecolorallocate($image, 0, 0, 0); //sets the background color
$color = imagecolorallocate($image, $red, $green, $blue); //sets the polygon color
imagefilledpolygon($image, $points, $vertices, $color); //draws the polygon
header("Content-type: image/png");
imagepng($image);
}
RandomShape(rand(3,10), rand(25,200)); //DO IT!!!!!
//@credits: onion2k - ShapeGenerator
?>
Im actually pretty satisfied how this came out, concidering its one of the few scripts I've made using polymorphic functions.