0
A
回答
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
相關問題
- 1. 驗證laravel中是否有多個字段同時唯一5
- 2. 是否Laravel 4.x文檔在錯誤中擴展身份驗證?
- 3. Laravel 4擴展分頁類
- 4. Laravel 4 - 是否可以擴展DB類?
- 5. route.MapPageRoute一個頁面,擴展
- 6. 擴展laravel登錄驗證
- 7. Laravel 4 jQuery的一個「部分驗證」
- 8. 如何在Laravel中擴展多個類?
- 9. 在Laravel中擴展多個類
- 10. Yii的驗證碼擴展
- 11. 如何在一個頁面中使用多個驗證
- 12. Laravel 4自定義驗證規則 - 在哪裏擴展驗證器?
- 13. 是否有可能在PHP擴展中有多個類?
- 14. Laravel 4 - 如何驗證多個字段的唯一性?
- 15. 驗證一個字符串是否在一個特定的代碼頁
- 16. Laravel - 擴展一個ResourceController
- 17. 是否有可能擴展一個庫類擴展MY_Controller類
- 18. Bean驗證驗證一個驗證是否有效?
- 19. 帶有多個驗證組的頁面總是返回TRUE Page.IsValid
- 20. Laravel-4驗證
- 21. Laravel 4驗證
- 22. Laravel驗證器檢查是否存在多個字段
- 23. 驗證對象是否有一個或多個關聯對象
- 24. 是否有可能知道一個類是否被擴展方法擴展?
- 25. Codeigniter多個表單在一個頁面上單獨驗證
- 26. asp.net mvc客戶端驗證多個表單在一個頁面
- 27. 是否可以有一個類擴展號碼?
- 28. Laravel驗證多個文件
- 29. Laravel多個驗證::嘗試
- 30. StackPanel中有多個擴展
這似乎更像是一個設計/用戶體驗的問題。單個驗證碼足以證明用戶不是機器人。 –
我同意安德烈......你應該首先弄清楚爲什麼你甚至需要多個驗證碼。 –
我有三種形式在同一頁面上,需要防止垃圾郵件 –