Question

So my home made captcha displays the text in a straight line but I think because of this, the bots can still sign up - they're getting in.

Can someone show me how to revise my code below to add a function or something that would make each letter display a little higher or lower than the other letters? Please don't mind the dirty coding as I'm not a PHP professional. Thank you everyone for your help.

$image = imagecreatetruecolor(70, 20); 

for ($i=0; $i < rand(20,40); $i++) {

$x = rand(0, 70);
$y = rand(0, 20);

imageline($image, $x, $y, $x+rand(0,10), $y+rand(0,240), imagecolorallocate($image,     rand(0,255),rand(0,190),rand(1,90)));

imageline($image, $x, $y, $x+rand(0,11), $y+rand(0,34), imagecolorallocate($image, 255,rand(50,240),rand(241,240)));

}
$s = rand(1, 240);
$x = rand(50, 240);
$f = rand(1, 4);
$d = rand(1, 1);
$c = rand(1, 4);

imagestring($image, $c, 3, $f, $_GET["T"], imagecolorallocate($image, $s,$x,$s));
imagestring($image, $c, 4, $f, $_GET["T"], imagecolorallocate($image, 255,rand(50,240),rand(241,240)));

imagecolortransparent($image, imagecolorallocate($image, 255, 0, 0));
imageinterlace($image);

header("Content-type: image/gif");
imagegif($image);
imagedestroy($image);
Was it helpful?

Solution

Le code...

$image = imagecreatetruecolor(70, 20); 

for ($i=0; $i < rand(20,40); $i++) {

$x = rand(0, 70);
$y = rand(0, 20);

imageline($image, $x, $y, $x+rand(0,10), $y+rand(0,240), imagecolorallocate($image, rand(0,255),rand(0,190),rand(1,90)));

imageline($image, $x, $y, $x+rand(0,11), $y+rand(0,34), imagecolorallocate($image, 255,rand(50,240),rand(241,240)));

}
$s = rand(1, 240);
$x = rand(50, 240);
$f = rand(1, 4);
$d = rand(1, 1);
$pos_x = rand(5,10);

$strArr = str_split($_GET["T"]);
foreach ($strArr as $str){
    $font_size = rand(1, 5); // range from 1-5
    imagestring($image, $font_size, $pos_x, $f, $str, imagecolorallocate($image, $s,$x,$s));
    imagestring($image, $font_size, $pos_x, $f, $str, imagecolorallocate($image, 255,rand(50,240),rand(241,240)));
    $pos_x = $pos_x + rand(20,30); //adjust your letter spaceing, depend on max char per chaptcha
}

imagecolortransparent($image, imagecolorallocate($image, 255, 0, 0));
imageinterlace($image);

header("Content-type: image/gif");
imagegif($image);
imagedestroy($image); 

nothing special, but functional by your requirements :) added rand size and rand letter space :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top