Changeset 3015 for trunk/system/controllers/captcha.php
- Timestamp:
- 07/09/2008 03:45:47 PM (5 months ago)
- Files:
-
- 1 modified
-
trunk/system/controllers/captcha.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/controllers/captcha.php
r3010 r3015 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 2 /** 3 * Allows a CAPTCHA image to be displayed dynamically. 4 * Captcha library is called to output the image. 5 * 6 * 7 * Usage: Call the captcha controller from a view. 8 * `echo html::image(url::site().'captcha');` 3 * Outputs the dynamic Captcha image. 4 * Usage: Call the Captcha controller from a view, e.g. 5 * <img src="<?php echo url::site('captcha') ?>" /> 9 6 * 10 7 * $Id$ 11 8 * 12 * @package C ore9 * @package Captcha 13 10 * @author Kohana Team 14 11 * @copyright (c) 2007-2008 Kohana Team … … 17 14 class Captcha_Controller extends Controller { 18 15 19 public $session;20 public $captcha;21 22 protected $captcha_code;23 24 16 public function index() 25 17 { 26 $this->session = Session::instance(); 27 $this->captcha = new Captcha; 28 29 // Create and store a random captcha string 30 $this->captcha_code = $this->create_code(); 31 $this->captcha->set_code($this->captcha_code); 32 $this->session->set('captcha_code', $this->captcha_code); 33 34 // Output the image 35 $this->captcha->render(); 36 } 37 38 private function create_code() 39 { 40 if (Config::item('captcha.style') === 'math') 41 { 42 $code = (string) mt_rand(101, 991); 43 } 44 else 45 { 46 $code = text::random('distinct', Config::item('captcha.num_chars')); 47 } 48 49 return $code; 18 // Output the Captcha challenge resource (no html) 19 $captcha = new Captcha; 20 $captcha->render(FALSE); 50 21 } 51 22
