CAPTCHA ikke sikker nok
For nogen tid siden lavede jeg et CAPTCHA sikkerhedstjek, men fandt ud af at det simpelthen ikke sikrer mit site.Jeg har erfaret at bots kommer igennem alligevel, hvad kan det skyldes?
I mit post script foretager jeg tjekket som det første.
Min kode:
<?
// Overordnet information
session_start();
header ("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$width = 250;
$height = 65;
$path = $_SERVER['PATH_TRANSLATED'];
$path_end = end(explode("/", $path));
$path_count = strlen($path_end);
$root_path = substr($path, 0, -$path_count);
// Opbyg billedet
$im = imagecreatetruecolor($width, $height);
// Lav baggrundsstøj i grafikken
for($i = 0; $i <= (($width + 1) * ($height + 1)); $i++) {
$bg_color = imagecolorallocate($im, rand(100, 255), rand(100, 255), rand(100, 255));
imagesetpixel($im, $x, $y, $bg_color);
if($x > $width) {
$x = -1;
$y++;
}
$x++;
}
//Påsæt teksten
$x = 10;
$font_dir = $root_path .'font/';
$font = array("katskratch.ttf", "serial.ttf", "rougd.ttf", "darkside.ttf", "wakiw.ttf");
$pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for($i = 1; $i <= 5; $i++) {
$rand_color = imagecolorallocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
$rand_font = rand(0, 4);
$rand_vinkel = rand(-10, 15);
$rand_text = $pattern{rand(0,25)};
#font size og y placering redigering
switch($rand_font) {
case(0): $y = 50; $size = 40; break;
case(1): $y = 50; $size = 70; break;
case(2): $y = 50; $size = 40; break;
case(3): $y = 58; $size = 50; break;
case(4): $y = 62; $size = 45; break;
case(4): $y = 65; $size = 45; break;
}
imagettftext($im, $size, $rand_vinkel, $x, $y, $rand_color, $font_dir . $font[$rand_font], $rand_text);
$info = $info. $rand_font;
$text = $text . $rand_text;
$x += 45;
}
//Påsæt random cirkler og streger
$min = 1;
$max = rand(10, 20);
for($i = $min; $i <= $max; $i++) {
$rand_color = imagecolorallocate($im, rand(100, 200), rand(100, 200), rand(100, 200));
$rand_x1 = rand(1, $width);
$rand_y1 = rand(1, $height);
$rand_x2 = rand(1, $width);
$rand_y2 = rand(1, $height);
$rand_width = rand(1, 60);
$rand_height = rand(1, 60);
$rand_figur = rand(1, 100);
if($rand_figur >= 60) {
imageline($im, $rand_x1, $rand_y1, $rand_x2, $rand_y2, $rand_color);
}else{
imageellipse($im, $rand_x1, $rand_y1, $rand_width, $rand_height, $rand_color);
}
}
// Opret session til sikkerhedstjekket
$_SESSION[captcha] = $text;
// TEST OUTPUT
#$text_color = imagecolorallocate($im, 0, 0, 0);
#imagestring($im, 5, 5, 60, "TestFont: ". $info, $textcolor);
#imagestring($im, 5, 5, 80, "TestText: ". $text, $textcolor);
// Afslut billedet
imagepng($im);
imagedestroy($im);
?>
