session_start();
// dbconnect.php
include('dbconnect.php');
$time = date("Y-m-j H:i:s");
$letters = range('a','z');
$numbers = range(1,26);
$string = "";
for ($i = strlen($string); $i < 6; $i++) {
$rand = mt_rand(0,25);
$string[] = $letters[$rand];
unset($rand);
}
for ($i = strlen($string); $i < 12; $i++) {
$rand = mt_rand(0,25);
$string[] = $numbers[$rand];
unset($rand);
}
shuffle($string);
for ($i = 0; $i < count($string); $i++) {
$r_string .= $string[$i];
}
$r_string = substr($r_string,0,6);
$_SESSION['r_string'] = $r_string;
// in die Datenbank eintragen
$sql = "INSERT INTO captcha (sign, time)";
$sql .= "values ('{$_SESSION['r_string']}','{$time}');";
// echo $sql; Testausgabe
$result = mysql_query($sql);
$font = mt_rand(1,5);
$necwidth = (strlen($r_string)*imagefontwidth($font)) + 10;
$necheight = imagefontheight($font) + 10;
if ($necwidth < 140) { $necwidth = 140; }
if ($nechright < 40) { $necheight = 40; }
$image = imagecreate($necwidth, $necheight);
$black = imagecolorallocate($image, 0, 0, 0);
$yellow = imagecolorallocate($image, 255,255,0);
$red = imagecolorallocate($image, 255,0,0);
$white = imagecolorallocate($image, 255,255,255);
$green = imagecolorallocate($image, 7, 255, 20);
$blue = imagecolorallocate($image, 12, 0, 255);
imagefill($image,0,0,$black); // Füllen mit $black vom Punkt 0|0 aus, Start in der oberen linken Ecke
imagerectangle($image,10,10,130,20,$yellow); // Rechteck vom Punkt 10|10 aus bis zum Punkt 130|20, füllen mit $yellow
imagerectangle($image, 40,0,60,40, $blue);
imageline($image, 10,0,10,40,$red); // Linie vom Punkt 10|0 zum Punkt 10|40 in $rot
imageline($image,0,20,140,20,$green);
imageline($image,0,$necheight,$necwidth,0,$blue);
imagestring($image,$font,12,12,$r_string,$white);
header("content-type: image/gif");
imagegif($image);
imagedestroy($image);