1

所以我自制的验证码以直线显示文本,但我认为正因为如此,机器人仍然可以注册 - 他们正在进入。

有人可以告诉我如何修改下面的代码以添加一个函数或使每个字母显示得比其他字母略高或略低的东西吗?请不要介意肮脏的编码,因为我不是 PHP 专业人士。感谢大家的帮助。

$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);
4

1 回答 1

0

乐码...

$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); 

没什么特别的,但可以满足您的要求 :) 增加了 rand 大小和 rand 字母空间 :)

于 2013-04-27T21:16:10.003 回答