Zufallszahl wird in der Cookie Variable „seckey“ gespeichert und kann von dort aus mit einer einfachen if-Abfrage geprüft werden.
<?php
if($_POST[seckey]==$_COOKIE[seckey]){
// Captchaverify okay
} else {
// Captchacode falsch
}
?>Beispielbild
Quelltext
<?php
$zufallszahl = mt_rand(10000, 99999);
setcookie("seckey", $zufallszahl);
header("Content-Type: image/png");
/* das Bild und seine Eigenschaften */
$im = imagecreate(61, 21); //das bilde erstellen
$bgcolor = imagecolorallocate($im, 255, 255, 255); //Backgroundcolor setzen
$fontcolor = imagecolorallocate($im, 0, 0, 0); //Schriftfarbe setzen
$gridcolor = imagecolorallocate($im, 128, 128, 128); //Schriftfarbe setzen
/* die Linien auf das Bild "zeichnen" */
for($x=0; $x <= 100; $x+=10)
imageline($im, $x, 0, $x, 50, $gridcolor);
for($y=0; $y <=50; $y+=5)
imageline($im, 0, $y, 100, $y, $gridcolor);
/* den Zahlencode auf das Bild "schreiben" */
imagestring($im, 5, 8, 3, $_COOKIE['seckey'], $fontcolor);
imagepng($im);
imagedestroy($im);
?>
