Welcome Guest, Not a member yet? Register   Sign In
captcha whitout database?
#1

[eluser]Unknown[/eluser]
i have a register form and need to use captcha but i dont khnow how i use this whitout data base .can i do it?

plz help me by example.tnx
#2

[eluser]mi6crazyheart[/eluser]
Go according to this. Hope it'll solve u'r problem.....
Code:
Instructions:

Load the plugin using:

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

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'     => './system/fonts/texb.ttf',
                    'img_width'     => '150',
                    'img_height' => 30,
                    'expiration' => 7200
                );
    
    $cap = create_captcha($vals);
    echo $cap['image'];
    

NOTES:
    
    The captcha function requires the GD image library.
    
    Only the img_path and img_url are required.
    
    If a "word" is not supplied, the function will generate a random
    ASCII string.  You might put together your own word library that
    you can draw randomly from.
    
    If you do not specify a path to a TRUE TYPE font, the native ugly GD
    font will be used.
    
    The "captcha" folder must be writable (666, or 777)
    
    The "expiration" (in seconds) signifies how long an image will
    remain in the captcha folder before it will be deleted.  The default
    is two hours.

RETURNED DATA

The create_captcha() function returns an associative array with this data:

  [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.


ADDING A DATABASE

In order for the captcha function to prevent someone from posting, 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 DB.

On the page where the captcha will be shown you'll have something like this:

    $this->load->plugin('captcha');
    $vals = array(
                    'img_path'     => './captcha/',
                    'img_url'     => 'http://example.com/captcha/'
                );
    
    $cap = create_captcha($vals);

    $data = array(
                    'captcha_id'    => '',
                    '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 '&lt;input type="text" name="captcha" value="" /&gt;';


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

    // First, delete old captchas
    $expiration = time()-7200; // Two hour limit
    $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 date > ?";
    $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";
    }

*/
#3

[eluser]Unknown[/eluser]
tnx.but i dont want to use data base !
#4

[eluser]zvineyard[/eluser]
[quote author="check" date="1271466656"]tnx.but i dont want to use data base ![/quote]

Check out: http://net.tutsplus.com/tutorials/php/bu...tact-form/
#5

[eluser]ranjeet_sangle[/eluser]
You can use this plugin..

Code:
$this->load->plugin('captcha');

no database is required for it..

you can go through the tutorial

http://ellislab.com/codeigniter/user-gui...ugins.html

Its very easy




Theme © iAndrew 2016 - Forum software by © MyBB