Welcome Guest, Not a member yet? Register   Sign In
Captcha plugin help
#1

[eluser]frist44[/eluser]
Hi - I'm trying to get the captcha plugin to work for me. I'm developing on WAMP and have loaded the plugin in my controller along with:

$vals = array(
'img_path' => 'C:/wamp/www/test/img/captcha',
'img_url' => base_url() . 'img/captcha/',
);

$cap = create_captcha($vals);

When I load the view, I get an empty graphic, with the following img tag:

<img src="http://localhost/test/img/captcha/1248107444.3059.jpg" width="150" height="30" style="border:0;" alt=" " />

However, there is no file with that name in the directory. I had read that the directory needed to be writable. I allowed the "everyone" group all priveleges just for testing and it still didn't work. I know most people are probably working with Linux and Apache, but didn't know if something different needed to be done for WAMP on Windows.

Any helps would be appreciated.

Thanks,
Brandon
#2

[eluser]slowgary[/eluser]
I don't know much about the captcha plugin, but there doesn't need to be a file with that name in the directory. It's likely that "1248107444.3059.jpg" is just a parameter being sent to a PHP function. When it says the directory needs to be writable, it's usually best if you set the permissions on that directory to 777.
#3

[eluser]frist44[/eluser]
I did some more testing and the 1248107444.3059.jpg was indeed the file name. The plugin creates a file for every request on disk and stores the jpg image. The 1248107444.3059.jpg was the filename from the html, not any query string.

Since I'm on Windows the 777 didn't really translate to the same meaning. After using the plugin for a little while, i decided to abandon it for another one that just uses the session to store the word and generates the images on the fly, rather than storing them on disk.

Thanks!
#4

[eluser]Thorpe Obazee[/eluser]
Perhaps you should use "http://localhost/test/img/captcha/" for your img_path?
#5

[eluser]bigtony[/eluser]
Try
Code:
'img_path' => './captcha/',
'img_url' => site_url() . 'captcha/',
#6

[eluser]Zorancho[/eluser]
This is how i do it with using the session class instead of database:
Code:
class Login extends Controller{
  function Login()
  {
    parent::Controller();
    //Load the plugin
    $this->load->plugin('captcha');
  }

  function index()
  {
   //If there is already session for captcha_word, put it in last_captcha_word.
   if($this->session->userdata('captcha_word'))
   {
     //New array to be inserted into the session userdata under key last_captcha_word
     $sess_data =
     array('last_captcha_word' =>strtolower($this->session->userdata('captcha_word')));

     //Set the key last_captcha_word with the word previously generated.
     $this->session->set_userdata($sess_data);
   }
   //Otherwise we don't have userdata key with captcha_word, so we will create new one
  
    //Values for the captcha, note that img_url worked for me if i put something like:
    //http://mywebsite.com/images/captcha
    //it will expire in 2 minutes.
    $vals = array(
    'img_path' => './images/captcha/',
    'img_url'     => base_url().'images/captcha/',
    'font_path'     => '../fonts/font.ttf',
    'img_width'     => '200',
    'img_height' => 50,
    'expiration' => 120
    );
    
    //Create the captcha and assign it to an array cap.
    $cap = create_captcha($vals);

    //Create session userdata with key captcha_word and value of the $cap['word'] key.
    $sess_new_data = array('captcha_word' => strtolower($cap['word']));
    $this->session->set_userdata($sess_new_data);

    //Send the $cap array to the view so we can print out the image.
    $data['cap'] = $cap;
    $this->load->view('login_form', $data);
  }

  function do_login()
  {
    //Get the $_POST values
    $user = $this->input->post('user');
    $captcha = $this->input->post('captcha');

    //Compare the posted captcha against the one in the session.
    if(strtolower($captcha) != $this->session->userdata('captcha_word'))
    {
        //If incorrect, set flash data and warn the user of it
        $this->session->set_flashdata('warning', 'Wrong captcha');
        redirect('login');
    }
    //Entered captcha is correct, continue with the script.
    else
    {
      //Do login
    }
  }
}

//And the view is this:
&lt;?php echo form_open('login/do_login'); ?&gt;
<label>Username:</label>
&lt;input type="text" name="user[username]"/&gt;
<label>Password:</label>
&lt;input type="password" name="user[password]" /&gt;
<br/><br/><br/>
&lt;?php
   //Print out the image from the $cap array.
?&gt;
<p>
    &lt;?php echo $cap['image']; ?&gt;<br />
    <label for="captcha">Captcha</label>
    &lt;input id="captcha" type="text" name="captcha" /&gt;
</p>
&lt;input type="submit" value="Login" /&gt;
&lt;?php echo form_close(); ?&gt;
Every time the user comes to Login/index... i check if there is session userdata for captcha word, if there is, i put it in old_captcha_word, otherwise i put new captcha_word in the session userdata.
If there is anything wrong with this, please message me... I think CodeIgniter has very good class for Sessions, much better to use with captcha (according to me) than database.
Zoran
#7

[eluser]Zorancho[/eluser]
Note:
You have to create folder images on the same level as the system folder and inside put another folder called captcha. Smile
Session class is the thing i like most about CodeIgniter, there are some really cool stuff you can do with it, i think it's the most complete one and most useful.




Theme © iAndrew 2016 - Forum software by © MyBB