error in captcha:

134 views
Skip to first unread message

abigail pattugalan

unread,
Apr 13, 2019, 10:22:40 AM4/13/19
to f3-fra...@googlegroups.com
hello everyone,

I am trying to use captcha to avoid bots,, but I am unsuccessful.

In the documentation it says the path of the font should be a subfolder inside UI, which I did, but I am receiving this error: imagettfbbox(): Could not find/open font. rather than using other captcha, I want to use the built-in captcha of F3.

can anyone help me pls by providing a working sample.

thank you




ved

unread,
Apr 13, 2019, 11:00:30 AM4/13/19
to Fat-Free Framework
Hi,

Please post your code.

abigail pattugalan

unread,
Apr 13, 2019, 12:03:04 PM4/13/19
to Fat-Free Framework

routes.ini
GET /captcha = cSecurity->captcha



config.ini
[globals]

DEBUG=3
UI=app/views/


cSecurity.php
<?php
class cSecurity extends Controller {

function captcha() {
$img = new Image();
$img->captcha('chock-a-block.ttf',20,4,'SESSION.captcha_code');
$img->render();
}
}


when i run it i receive this error

Internal Server Error

imagettfbbox(): Could not find/open font

[D:/systems2019/web/login/htdocs/lib/base.php:2261] Base->error()
[D:/systems2019/web/login/htdocs/lib/image.php:421] imagettfbbox()
[D:/systems2019/web/login/htdocs/app/controllers/cSecurity.php:6] Image->captcha()
[D:/systems2019/web/login/htdocs/lib/base.php:1873] cSecurity->captcha()
[D:/systems2019/web/login/htdocs/lib/base.php:1673] Base->call()
[D:/systems2019/web/login/htdocs/index.php:20] Base->run()


hope someone help me, thank you

On Saturday, April 13, 2019 at 6:00:30 PM UTC+3, ved wrote:
Hi,

Please post your code.

ved

unread,
Apr 13, 2019, 12:13:38 PM4/13/19
to f3-fra...@googlegroups.com
Hi,

Some things to consider/try:
Is the font directly inside your UI folder? And not inside a "fonts" subfolder?
Is the filename correct? Capitalization may be an issue and "chock-a-block.ttf" may be different from "Chock-a-Block.ttf" on some systems. (although I'm not entirely sure if the framework takes this into account)
Have you tried a different font?

Also, consider using Google's recaptcha instead, which I'm guessing may be more secure and usable than the F3's plugin.

abigail pattugalan

unread,
Apr 13, 2019, 12:24:59 PM4/13/19
to f3-fra...@googlegroups.com
answer to your questions:

font is inside UI folder which is app/views
so font is foundin app/views/fonts
the filename is correct.

though interested to use google but i prefer to use F3.

kindly help pls

thank you

ved

unread,
Apr 13, 2019, 12:45:34 PM4/13/19
to Fat-Free Framework
So, your font is at "app/views/fonts/chock-a-block.ttf"

Your code must be:

$img->captcha('fonts/chock-a-block.ttf',20,4,'SESSION.captcha_code');


Good luck.

abigail pattugalan

unread,
Apr 13, 2019, 12:50:44 PM4/13/19
to Fat-Free Framework
Well i did that, my source is the same as your recommendation.

I am using xampp, the latest one, portable version

ved

unread,
Apr 13, 2019, 12:57:29 PM4/13/19
to Fat-Free Framework
Hi,

Well now you're just giving us wrong information then, because you just posted this:

On Saturday, April 13, 2019 at 5:03:04 PM UTC+1, abigail pattugalan wrote:
cSecurity.php
<?php
class cSecurity extends Controller {

function captcha() {
$img = new Image();
$img->captcha('chock-a-block.ttf',20,4,'SESSION.captcha_code');
$img->render();
}
}


Which is not using the "fonts" subfolder, so that is not what you've just stated.

Anyway, try and use the complete windows path then, like: "D:\systems2019\web\login\htdocs\app\views\fonts\chock-a-block.ttf" to test if it finds the font.

abigail pattugalan

unread,
Apr 13, 2019, 1:02:11 PM4/13/19
to Fat-Free Framework
Sorry for my mistake I should have said that i did that too, changed my code from previous one to yours, actually i experimented with the path of the font, no good result. Sorry for such mistake

ved

unread,
Apr 13, 2019, 1:41:41 PM4/13/19
to Fat-Free Framework
Well, I've exhausted all my suggestions then :-/

Sorry I couldn't be of more help. Maybe somebody else will chip in with some more suggestions.

Good luck. 

xfra35

unread,
Apr 14, 2019, 3:10:12 AM4/14/19
to Fat-Free Framework
Hi,

the error says "could not find/open font", so maybe for some reason, the ttf is not readable.

Have you tried another ttf ?

abigail pattugalan

unread,
Apr 14, 2019, 4:08:12 AM4/14/19
to f3-fra...@googlegroups.com
Hello Sir, I tried it too, still not working.
I tried different font, stil the same, not working.

bcosca

unread,
Apr 14, 2019, 6:19:40 AM4/14/19
to f3-fra...@googlegroups.com
Did you check the permissions on the folder and font files? What does GDFONTPATH return?

abigail pattugalan

unread,
Apr 14, 2019, 6:31:26 AM4/14/19
to f3-fra...@googlegroups.com
Hello Sir,

getting the GDFONTPATH shows nothing.
I think there should be flexibility putting the font file anywhere, perhaps in public folder?

ved

unread,
Apr 14, 2019, 3:21:32 PM4/14/19
to Fat-Free Framework
Hi again, this was bugging me a bit.

So, I've installed xampp portable and tried to replicate OP's problem (I usually only work on linux systems) and can confirm that this is in fact also happening on my end and appears to be an issue with the framework.

Following the documentation instructions gives me the same error as the OP.

Replacing line's 421 and 428 $path variable on the image.php plugin (which following the docs gets resolved into something like 'app/views/fonts/chock-a-block.ttf') with a fully hardcoded path (on my case: 'D:\xampp\htdocs\app\views\fonts\chock-a-block.ttf') makes the captcha image work correctly. 

So I'm assuming there's some issue with path resolution, maybe just on windows systems or something but there's definitely an issue imho.

My test code is pretty basic, it follows the documentation example and is pretty much the same as OPs.

<?php
$f3
= require('lib/base.php');
$f3
->set('DEBUG', 3);
$f3
->set('UI', 'app/views/');

$f3
->route('GET /',
   
function() {        
       $img
= new Image();
       $img
->captcha('fonts/chock-a-block.ttf',16,5,'SESSION.captcha_code');
       $img
->render();
   
}
);
$f3
->run();

Then, place a font inside an app/views/fonts folder and access it. The error is there and it's the same as OPs, at least on my end.

So, I'd recommend @abigail pattugalan to open an issue on Github to have this checked out and eventually fixed by the devs.

Hope it helps, cheers.





bcosca

unread,
Apr 14, 2019, 7:40:57 PM4/14/19
to f3-fra...@googlegroups.com
captcha() has a 5th argument where you can specify the canonical path to the font file in case your OS is incapable of resolving the path properly.

ved

unread,
Apr 14, 2019, 8:14:06 PM4/14/19
to Fat-Free Framework
You are right. Sorry, I completely missed that.

I've just tested on my end and can confirm that it does in fact work correctly by setting the full path to the fonts folder on the 5th parameter like so:

$img->captcha('chock-a-block.ttf',20,4,'SESSION.captcha_code', 'D:/xampp/htdocs/app/views/fonts/');

Cheers

abigail pattugalan

unread,
Apr 15, 2019, 3:06:13 AM4/15/19
to Fat-Free Framework
Let me try this if it will work.
will reply soon to the result.
thank you

abigail pattugalan

unread,
Apr 15, 2019, 3:11:35 AM4/15/19
to Fat-Free Framework
Yes is it working now.

thank you so much for your kind help.
appreciated

abigail pattugalan

unread,
Apr 15, 2019, 3:49:18 AM4/15/19
to Fat-Free Framework
<?php

class cSecurity extends Controller {

    function captcha() {
       
        $path = $this->f3->get("ROOT");
        $path = str_replace("\\", "/", $path) . '/public/fonts/';

        $img = new Image();
        
        $img->captcha('chock-a-block.ttf',16,5,'SESSION.captcha_code', $path);
        $img->render();
    }
}

my source above, working perfectly
Reply all
Reply to author
Forward
0 new messages