Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Captcha problem
#1

[eluser]Unknown[/eluser]
Hello,

I read the tutorial about captcha, watched also some tutorials on the web but i couldn't find a working solution for me. I am just trying to generate a captcha image. The captcha folder is in my root folder. In my case it look like this:
localhost
--rootfolder
+application
+system
+captcha

I made a captcha controller:

Code:
class Captcha extends CI_Controller {
    
    
    public function index(){
        
        
        $this->load->helper(array('captcha', 'url'));
        
        $capt = array(
            'word' => 'Random 123',
            'img_path' => './captcha/',
            'image_url' => base_url().'captcha/',
            'img_width' => '300',
            'img_height' => '50',
            'expiration' => '3600',
        );
        
        $img = create_captcha($capt);
        $data['image'] = $img['image'];
        $this->load->view('main', $data);
    }
}

And a view file:
Code:
<h1>and here comes CAPTCHA</h1>

&lt;?php echo $image;?&gt;

What am I doing wrong? Please help!

Thank you in advance!
#2

[eluser]ivantcholakov[/eluser]
I don't use the original captcha, so I can't help a lot. Anyway, from what I see, this line looks suspicious:

Code:
'image_url' => base_url().'captcha/',

Change it:

Code:
'image_url' => base_url().'/captcha/',

Or:

Code:
'image_url' => base_url('captcha').'/',
#3

[eluser]Unknown[/eluser]
[quote author="ivantcholakov" date="1389642032"]I don't use the original captcha, so I can't help a lot. [/quote]


Thank you, sir. And thank God the problem is solved. Actually it was the base_url function + .htaccess.

I set the base_url() in config.php to:

Code:
$config['base_url'] = 'localhost/ci/';

Then the capcha generator looks like this:

Code:
&lt;?php $vals = array(
    'word' => 'Random word',
    'img_path' => './captcha/',
    'img_url' => 'captcha/',
    'img_width' => '150',
    'img_height' => 30,
    'expiration' => 7200
    );

$cap = create_captcha($vals);
echo 'Submit the word you see below:';
echo $cap['image'];
echo '&lt;input type="text" name="captcha" value="" /&gt;';

And finally the .htaccess file:
Code:
RewriteCond $1 !^(index\.php|css|fonts|images|js|captcha|robots\.txt)

So this is it.
#4

[eluser]CroNiX[/eluser]
[quote author="ivantcholakov" date="1389642032"]I don't use the original captcha, so I can't help a lot. Anyway, from what I see, this line looks suspicious:

Code:
'image_url' => base_url().'captcha/',

Change it:

Code:
'image_url' => base_url().'/captcha/',

Or:

Code:
'image_url' => base_url('captcha').'/',
[/quote]
base_url() already contains the trailing slash, or at least it is supposed to, so
Code:
base_url().'/captcha/'
would end up with a double slash before "captcha": http://yoursite.com//captcha/
#5

[eluser]ivantcholakov[/eluser]
@CroNiX

You are right, base_url() without an argument returns a result with the last slash.
#6

[eluser]Tpojka[/eluser]
It is a good practice putting uri in parenthesis of base href.

Code:
if ('captcha' == $uri)
{
  //  base_url('captcha');
}




Theme © iAndrew 2016 - Forum software by © MyBB