basic.php (2059B)
1 <?php 2 class ControllerExtensionCaptchaBasic extends Controller { 3 public function index($error = array()) { 4 $this->load->language('extension/captcha/basic'); 5 6 if (isset($error['captcha'])) { 7 $data['error_captcha'] = $error['captcha']; 8 } else { 9 $data['error_captcha'] = ''; 10 } 11 12 $data['route'] = $this->request->get['route']; 13 14 return $this->load->view('extension/captcha/basic', $data); 15 } 16 17 public function validate() { 18 $this->load->language('extension/captcha/basic'); 19 20 if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) { 21 return $this->language->get('error_captcha'); 22 } 23 } 24 25 public function captcha() { 26 $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6); 27 28 $image = imagecreatetruecolor(150, 35); 29 30 $width = imagesx($image); 31 $height = imagesy($image); 32 33 $black = imagecolorallocate($image, 0, 0, 0); 34 $white = imagecolorallocate($image, 255, 255, 255); 35 $red = imagecolorallocatealpha($image, 255, 0, 0, 75); 36 $green = imagecolorallocatealpha($image, 0, 255, 0, 75); 37 $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); 38 39 imagefilledrectangle($image, 0, 0, $width, $height, $white); 40 imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red); 41 imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green); 42 imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue); 43 imagefilledrectangle($image, 0, 0, $width, 0, $black); 44 imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black); 45 imagefilledrectangle($image, 0, 0, 0, $height - 1, $black); 46 imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black); 47 48 imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black); 49 50 header('Content-type: image/jpeg'); 51 52 imagejpeg($image); 53 54 imagedestroy($image); 55 exit(); 56 } 57 }