Forum Moderators: coopster

Message Too Old, No Replies

Upload fonts to a directory and have them automatically used and rando

         

eSite

10:25 am on Jul 13, 2006 (gmt 0)



Ok so I'm trying to modify a PHP script from a blogging tool.
The script generates a CAPTCHA using a single and same .ttf for all installations.
I find that is is a vulnerability issue, consequently I would like to add several fonts and have them automatically used and randomly selected.

$font_face= "texb.ttf";

$font_face is the filename (with its extension) of the font that will actually be used for the CAPTCHA
$font_path = PATH.'fonts/'.$font_face;

$font_path is the full path to that same font, not to its directory!

For an easy hack to implement, the fonts should be sorted from their directory before $font_face is set.
Note : there is an index.html to ignore in that directory.
And $font_face should be the random font.

How do I do this in PHP4?

whoisgregg

2:55 pm on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps some of the examples on the readdir [php.net] manual page will get you started in the right direction?

Once you have an array of file names, looping through and testing for a particular extension should be pretty straightforward.

dreamcatcher

6:17 pm on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$fonts = array();

$dir = opendir(PATH.'fonts/');

while ($read = readdir($dir))
{

if ($read!='.' && $read!='..' && $read!='index.html')
{

$fonts[] = $read;

}

}

closedir($dir);

shuffle($fonts);

$font_path = PATH.'fonts/'.$fonts[0];

Something like that should get you started.

dc