From 8ede1a2ecbb62577afd32996956c5feaf7ddf9b6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 13:34:52 -0500 Subject: replacing the old HTML user guide with a Sphinx-managed user guide --- user_guide/helpers/captcha_helper.html | 195 --------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 user_guide/helpers/captcha_helper.html (limited to 'user_guide/helpers/captcha_helper.html') diff --git a/user_guide/helpers/captcha_helper.html b/user_guide/helpers/captcha_helper.html deleted file mode 100644 index 991c2d3f1..000000000 --- a/user_guide/helpers/captcha_helper.html +++ /dev/null @@ -1,195 +0,0 @@ - - - - - -CAPTCHA Helper : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

CAPTCHA Helper

- -

The CAPTCHA Helper file contains functions that assist in creating CAPTCHA images.

- - -

Loading this Helper

- -

This helper is loaded using the following code:

-$this->load->helper('captcha'); - -

The following functions are available:

- -

create_captcha($data)

- -

Takes an array of information to generate the CAPTCHA as input and creates the image to your specifications, returning an array of associative data about the image.

- -[array]
-(
-  'image' => IMAGE TAG
-  'time' => TIMESTAMP (in microtime)
-  'word' => CAPTCHA WORD
-)
- -

The "image" is the actual image tag: -<img src="http://example.com/captcha/12345.jpg" width="140" height="50" />

- -

The "time" is the micro timestamp used as the image name without the file - extension. It will be a number like this: 1139612155.3422

- -

The "word" is the word that appears in the captcha image, which if not - supplied to the function, will be a random string.

- -

Using the CAPTCHA helper

- -

Once loaded you can generate a captcha like this:

- -$vals = array(
-    'word' => 'Random word',
-    'img_path' => './captcha/',
-    'img_url' => 'http://example.com/captcha/',
-    'font_path' => './path/to/fonts/texb.ttf',
-    'img_width' => '150',
-    'img_height' => 30,
-    'expiration' => 7200
-    );
-
-$cap = create_captcha($vals);
-echo $cap['image'];
- - - -

Adding a Database

- -

In order for the captcha function to prevent someone from submitting, you will need - to add the information returned from create_captcha() function to your database. - Then, when the data from the form is submitted by the user you will need to verify - that the data exists in the database and has not expired.

- -

Here is a table prototype:

- -CREATE TABLE captcha (
- captcha_id bigint(13) unsigned NOT NULL auto_increment,
- captcha_time int(10) unsigned NOT NULL,
- ip_address varchar(16) default '0' NOT NULL,
- word varchar(20) NOT NULL,
- PRIMARY KEY `captcha_id` (`captcha_id`),
- KEY `word` (`word`)
-);
- -

Here is an example of usage with a database. On the page where the CAPTCHA will be shown you'll have something like this:

- -$this->load->helper('captcha');
-$vals = array(
-    'img_path' => './captcha/',
-    'img_url' => 'http://example.com/captcha/'
-    );
-
-$cap = create_captcha($vals);
-
-$data = array(
-    'captcha_time' => $cap['time'],
-    'ip_address' => $this->input->ip_address(),
-    'word' => $cap['word']
-    );
-
-$query = $this->db->insert_string('captcha', $data);
-$this->db->query($query);
-
-echo 'Submit the word you see below:';
-echo $cap['image'];
-echo '<input type="text" name="captcha" value="" />';
- -

Then, on the page that accepts the submission you'll have something like this:

- -// First, delete old captchas
-$expiration = time()-7200; // Two hour limit
-$this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);
-
-// Then see if a captcha exists:
-$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
-$binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
-$query = $this->db->query($sql, $binds);
-$row = $query->row();
-
-if ($row->count == 0)
-{
-    echo "You must submit the word that appears in the image";
-}
- -
- - - - - - - -- cgit v1.2.3-24-g4f1b