PHP Captcha not working

Status
Not open for further replies.

jack202872

New Member
Messages
13
Reaction score
0
Points
0
Hello,

I wanted to create a captcha to prevent bots from posting on my site. But the php code i use works locally but not online.
Does anybody have any idea why?

<?php
session_start();
function motListe()
{
$liste = array(*list of words*);
return $liste[array_rand($liste)];
}

function image($mot)
{
$size = 32;
$marge = 15;
$font = './angelina.ttf';

$matrix_blur = array(
array(1,1,1),
array(1,1,1),
array(1,1,1));

$box = imagettfbbox($size, 0, $font, $mot);
$largeur = $box[2] - $box[0];
$hauteur = $box[1] - $box[7];
$largeur_lettre = round($largeur/strlen($mot));

$img = imagecreate($largeur+$marge, $hauteur+$marge);
$blanc = imagecolorallocate($img, 255, 255, 255);
$noir = imagecolorallocate($img, 0, 0, 0);

$couleur = array(
imagecolorallocate($img, 0x99, 0x00, 0x66),
imagecolorallocate($img, 0xCC, 0x00, 0x00),
imagecolorallocate($img, 0x00, 0x00, 0xCC),
imagecolorallocate($img, 0x00, 0x00, 0xCC),
imagecolorallocate($img, 0xBB, 0x88, 0x77));

for($i = 0; $i < strlen($mot);++$i)
{
$l = $mot[$i];
$angle = mt_rand(-25,25);
imagettftext($img,$size,$angle,($i*$largeur_lettre)+$marge, $hauteur+mt_rand(0,$marge/2),$couleur[array_rand($couleur)], $font, $l);
}


imageline($img, 2,mt_rand(2,$hauteur), $largeur+$marge, mt_rand(2,$hauteur), $noir);
imageline($img, 2,mt_rand(2,$hauteur), $largeur+$marge, mt_rand(2,$hauteur), $noir);


imageconvolution($img, $matrix_blur,9,0);

imagepng($img);
imagedestroy($img);
}


function captcha()
{
$mot = motListe();
$_SESSION['captcha'] = $mot;
image($mot);
}

header("Content-type: image/png");
captcha();
?>
 

jack202872

New Member
Messages
13
Reaction score
0
Points
0
There is a white square, where there should be a real image, with a word to be copied to be allowed to post.
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
What is the browser reporting for the request (you'll need to use your browser's developer tools or Firebug)? And are you checking the error log at the server? What happens if you call the image page directly rather the via an IMG tag?
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
Hi jack202872,

Make sure you have the angelina.ttf font uploaded on to your server.

I’m able to reproduce your problem if that file is missing and it works as expected if the file is in place.
 

jack202872

New Member
Messages
13
Reaction score
0
Points
0
That's it ! Thank you. The font was upload, but the extension was in upper case.

Thanks again.

---------- Post added at 09:45 PM ---------- Previous post was at 09:43 PM ----------

:smile:
 
Status
Not open for further replies.
Top