2014-12-24 31 views
0

我在我的項目中使用了mews/captcha插件。 但問題是我不能在同一頁面添加多個驗證碼。Laravel 4:在一個頁面中是否有多個驗證碼的擴展?

感謝&問候, Monang沙阿

+1

這似乎更像是一個設計/用戶體驗的問題。單個驗證碼足以證明用戶不是機器人。 –

+0

我同意安德烈......你應該首先弄清楚爲什麼你甚至需要多個驗證碼。 –

+0

我有三種形式在同一頁面上,需要防止垃圾郵件 –

回答

0

而不是使用的馬廄/驗證碼的,我有相同的使用習慣驗證碼。使用

{{ Form::image(SITE_URL."get-captcha/captcha1?".time(),'Captcha image',array('id'=>'captcha1')) }} 

注意

public function get_captcha($id, $width = 120, $height = 30) {  
     $config = array(
      'fontsizes' => array(14, 15, 16, 17, 18), 
      'length' => 5, 
      'width' => $width, 
      'height' => $height, 
      'space' => 20, 
      'colors' => array('128,23,23', '128,23,22', '33,67,87', '67,70,83', '31,56,163', '48,109,22', '165,42,166', '18,95,98', '213,99,8'), 
      'sensitive' => false, // case sensitive (params: true, false) 
      'quality' => 80 // image quality 
     ); 

     $fonts = $backgrounds = array(); 
     $assets = __DIR__ . '/../../../captcha/'; 
     foreach (glob($assets . '*.ttf') as $filename) { 
      $fonts[] = $filename; 
     } 
     foreach (glob($assets . '*.png') as $filename) { 
      $backgrounds[] = $filename; 
     } 

     $char = Str::random($config['length']); 

     Session::put('captchaHash'.$id, ($config['sensitive'] === true ? $char : Str::lower($char))); 

     $bg_image = $backgrounds[rand(0, count($backgrounds) - 1)]; 

     $bg_image_info = getimagesize($bg_image); 
     if ($bg_image_info['mime'] == 'image/jpg' || $bg_image_info['mime'] == 'image/jpeg') 
     { 
      $old_image = imagecreatefromjpeg($bg_image); 
     } 
     elseif ($bg_image_info['mime'] == 'image/gif') 
     { 
      $old_image = imagecreatefromgif($bg_image); 
     } 
     elseif ($bg_image_info['mime'] == 'image/png') 
     { 
      $old_image = imagecreatefrompng($bg_image); 
     } 

     $new_image = imagecreatetruecolor($config['width'], $config['height']); 
     $bg = imagecolorallocate($new_image, 255, 255, 255); 
     imagefill($new_image, 0, 0, $bg); 

     imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $config['width'], $config['height'], $bg_image_info[0], $bg_image_info[1]); 

     $bg = imagecolorallocate($new_image, 255, 255, 255); 
     for ($i = 0; $i < strlen($char); $i++) 
     { 
      $color_cols = explode(',', $config['colors'][rand(0, count($config['colors']) - 1)]); 
      $fg = imagecolorallocate($new_image, trim($color_cols[0]), trim($color_cols[1]), trim($color_cols[2])); 
      imagettftext($new_image, $config['fontsizes'][rand(0, count($config['fontsizes']) - 1)], rand(-10, 15), 10 + ($i * $config['space']), rand($config['height'] - 10, $config['height'] - 5), $fg, $fonts[rand(0, count($fonts) - 1)], $char[$i]); 
     } 
     imagealphablending($new_image, false); 

     header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); 
     header('Pragma: no-cache'); 
     header("Content-type: image/jpg"); 
     header('Content-Disposition: inline; filename=' . $id . '.jpg'); 
     imagejpeg($new_image, null, $config['quality']); 
     imagedestroy($new_image); 
    } 

我有電話驗證碼圖片進入查看: captchaHash是動態生成每個驗證碼 - 請在下面找到的代碼: -

控制器功能。您可以下載驗證碼拉鍊//103.8.216.142/projects/captcha.zip到瀏覽器

感謝,Monang