Korzystam z klasy Auto generate CAPTCHA ze strony link w moim przypadku wygląda ona następująco:
plik captcha.inc.php
<?php class captcha { protected $code; private $width = 150; private $height = 35; private $length = 6; public function __construct($width = '', $height= '', $length = '') { $this->height = $height; } $this->width = $width; } $this->length = $length; } } public function getCaptchaCode(){ return $this->code; } public function showCaptchaImage() { $image = imagecreatetruecolor($this->width, $this->height); $height= imagesx($image); $width = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $red = imagecolorallocatealpha($image, 255, 0, 0, 75); $green = imagecolorallocatealpha($image, 0, 255, 0, 75); $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); imagefilledrectangle($image, 0, 0, $height, $width, $white); for($i = 0; $i<4; $i++){ } imagefilledrectangle($image, 0, 0, $height, 0, $black); imagefilledrectangle($image, $height- 1, 0, $height- 1, $width - 1, $black); imagefilledrectangle($image, 0, 0, 0, $width - 1, $black); imagefilledrectangle($image, 0, $width - 1, $height, $width - 1, $black); imagejpeg($image); imagedestroy($image); } } ?>
plik. captcha.php odpowiedzialny za generowanie obrazka
<?php include('captcha.inc.php'); $captcha = new Captcha(100,50,6); $_SESSION['captcha'] = $captcha->getCaptchaCode(); $captcha->showCaptchaImage(); ?>
i na koniec fragment tekstu odpowiedzialny za wyświetlanei captchy w formularzu + na czas testów wyświetlenie obok wartości przetrzymywanej w sesji captcha:
<tr> <td width="80" align="right"><img src="lib/captcha.php"></td><td><?php echo $_SESSION['captcha'];?></td> </tr>
Efekt jest taki że wartość wyświetlana w sesji jest kodem poprzedniego obrazka :/
Macie jakiś pomysł ?