ans = $a + $b + $c; break; case 2: $operator[1] = '-'; $this->ans = $a + $b - $c; break; case 3: $operator[1] = 'x'; $this->ans = $a + $b * $c; break; } break; case 2 : $operator[0] = '-'; switch(rand(1, 3)){ case 1: $operator[1] = '+'; $this->ans = $a - $b + $c; break; case 2: $operator[1] = '-'; $this->ans = $a - $b - $c; break; case 3: $operator[1] = 'x'; $this->ans = $a - $b * $c; break; } break; case 3 : $operator[0] = 'x'; switch(rand(1, 3)){ case 1: $operator[1] = '+'; $this->ans = $a * $b + $c; break; case 2: $operator[1] = '-'; $this->ans = $a * $b - $c; break; case 3: $operator[1] = 'x'; $this->ans = $a * $b * $c; break; } break; } $code = $a . $operator[0] . $b . $operator[1] . $c; /* show the answer => $code = $a . $operator[0] . $b . $operator[1] . $c; . '=' . $this->ans; */ unset($a, $b, $c, $operator); return $code; } function CaptchaSecurityImages($width = 110, $height = 40, $characters = 5) { $code = $this->generateCode(); /* font size will be 55% of the image height */ $font_size = $height * 0.6; $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/8; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/450; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code1'] = $this->ans; } } $captcha = new CaptchaSecurityImages(); unset($captcha); ?>