Welcome Guest, Not a member yet? Register   Sign In
an enhanced captcha as helper
#7

[eluser]Christian Rößler[/eluser]
Hy 'JP X3M',

First create a folder called
Code:
helpers
in
Code:
/system/application/
if not exists.
Then copy the helper-file into this directory.

After that create a writeable folder where the generated captcha-images will reside in:
Code:
/captcha/
Make shure this is writeable by the webserver / php-instance (chmod 777 for example).

Your example folder structure:
Code:
/system/
/system/application/
/system/application/helpers/
/system/application/helpers/captcha_helper.php
/captcha/

If you use apache's mod rewrite to hide index.php from your url, edit .htaccess to allow clients access to the captcha directory!

Finally write your controller (an example):
Code:
function  index(){
// load the captcha helper
$this->load->helper('captcha');

// create the captcha-config
$aCaptchaCfg = array(
  //'word'          => 'myrandomword',    //default: random()
  'length'        => 6,                         //default: 5
  'img_path'   => site_url().'captcha/',   //no default !
  'img_url'       => site_url().'captcha/',  // no default!
  'font_path'  => site_url().'system/fonts/', // default: ./system/fonts/
  'fonts'         => array('corsiva.ttf', 'TSCu_Comic.ttf'), // default: texb.ttf
  'font_size'     => 15,      // default: 18
  'img_width'  => '180',  // default: 170
  'img_height' => '60',   // default: 60
  'expiration' => 7200 // default: 7200
);
        
// get captcha-stuff
$aCaptcha = create_captcha($aCaptchaCfg);

// throw the captcha-array to your view and load the view
$data['aCaptcha'] = $aCaptcha;
$this->load->view('myview', $data);
}
Make sure to edit the line where you define the folders (img_path, font_path). Upload your own ttf-fonts into
Code:
/system/fonts/
.

Here is an example-view (really simple).
You'll have to improve this by using a form and validate the input (the captcha-word typed in by the user) and compare it with the generated captcha-secret.
Code:
<html>
<head><title>foobar</title></head>
<body>
  captcha-test:<br/>
  &lt;?=$aCaptcha['image']?&gt;<br/>
&lt;/body&gt;
&lt;/html&gt;

There are 3 keys in the generated Captcha-array:

Code:
$aCaptcha['image']
represents the image-html-tag to include the image-file into forms (<img src="..." />)

Code:
$aCaptcha['word']
The generated secret word. You'll need this one to compare the user-input with. If this word and the user-input are not equal, then republish the form because the captcha is wrong.

Code:
$aCaptcha['time']
The timecode when the captcha has been generated. I don't really need this...

Get more fonts here: http://www.fontasy.de/ (for example)
or here: google -> 'free fonts'


Messages In This Thread
an enhanced captcha as helper - by El Forum - 09-27-2007, 07:39 AM
an enhanced captcha as helper - by El Forum - 09-27-2007, 01:01 PM
an enhanced captcha as helper - by El Forum - 09-30-2007, 03:13 PM
an enhanced captcha as helper - by El Forum - 10-27-2007, 10:06 AM
an enhanced captcha as helper - by El Forum - 10-27-2007, 10:29 AM
an enhanced captcha as helper - by El Forum - 10-27-2007, 08:26 PM
an enhanced captcha as helper - by El Forum - 10-29-2007, 04:27 AM
an enhanced captcha as helper - by El Forum - 10-29-2007, 04:40 AM
an enhanced captcha as helper - by El Forum - 05-08-2008, 02:21 AM
an enhanced captcha as helper - by El Forum - 05-20-2008, 02:21 AM
an enhanced captcha as helper - by El Forum - 05-20-2008, 02:54 AM
an enhanced captcha as helper - by El Forum - 05-20-2008, 05:36 AM
an enhanced captcha as helper - by El Forum - 06-04-2008, 09:52 AM
an enhanced captcha as helper - by El Forum - 09-25-2008, 10:01 PM
an enhanced captcha as helper - by El Forum - 01-11-2009, 08:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB