Encore un captcha

cs_remib74 Messages postés 15 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 5 mars 2020 - 27 juil. 2014 à 12:04
cs_remib74 Messages postés 15 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 5 mars 2020 - 28 juil. 2014 à 08:44
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/100676-encore-un-captcha

cs_remib74 Messages postés 15 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 5 mars 2020
Modifié par cs_remib74 le 28/07/2014 à 08:45
salut Whismeril,désolé pour le formatage fantaisiste... en tout cas la source est à jour, je prévois maintenant d'ajouter le son au captcha et de faire passer la variable du texte dans une variable de session, a ++ sur codes-sources
Whismeril Messages postés 19029 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 26 avril 2024 656
27 juil. 2014 à 21:07
Bonsoir, il serait plus judicieux de mettre directement le code et la description à jour.
J'ai édité la description pour y ajouter la coloration syntaxique.
remib74 Messages postés 15 Date d'inscription dimanche 25 novembre 2012 Statut Membre Dernière intervention 20 octobre 2015
27 juil. 2014 à 15:12
petite mise à jour avec un apport du code
http://codes-sources.commentcamarche.net/source/100340-captcha
tester en ligne : http://codingandscripting.comli.com/captcha_php/

<?php
$capt = "";

$a = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');

if (!isset($_POST['Submit']) || isset($_POST['recapt'])) {
$i = range(0, 26);
$arr = range('A', 'Z');

$y = 1;
for ($y = 1; $y <= 1; $y++) {
$x = mt_rand($i[1], 25);
$capt = mt_rand($i[8], 26) . $arr[$x] . mt_rand($i[1], 26) . mt_rand($i[1], 26) . $arr[$x] . mt_rand($i[1], 26);
$width = 200;
$height = 100;
$dossier = 'img/';
$font = 'font/airstrea.ttf';
$fichier = basename($dossier . 'captcha_bck.jpg');
$image_dir = 'img/ico/';
$miniature = $image_dir . $fichier;
$im = ImageCreateTrueColor($width, $height)
or die("Erreur pour créer l'image");
$blanc = ImageColorAllocate($im, 255, 255, 255);
$gris = ImageColorAllocate($im, 50, 50, 50);
$source = ImageCreateFromJpeg($dossier . $fichier);
ImageCopyResampled($im, $source, 0, 0, 0, 0, $width, $height, $width, $height);

/* ajout de cercles */
$nbCircle = rand(7, 10);
$b = rand(0, 255);
$colorCircle = imagecolorallocate($im, $blanc,$blanc,$blanc);
for ($i = 0; $i < $nbCircle; $i++)
imageellipse($im, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $colorCircle);
imagettftext($im, 20, 17, 47, 67, $gris, $font, $capt);
imagettftext($im, 20, 20, 50, 70, $blanc, $font, $capt);

//ajout ligne
$nbLine = rand(5, 8);
for ($i = 0; $i < $nbLine; $i++) {
$r = rand(0, 255);
srand();
$v = rand(0, 255);
srand();
$b = rand(0, 255);
$color = imagecolorallocate($im, $r, $v, $b);
$x1 = rand(0, $width / 4);
srand();
$x2 = rand($width / 4, $width);
$y1 = rand(0, $height / 4);
srand();
$y2 = rand($height / 4, $height);
imageline($im, $x1, $y1, $x2, $y2, $color);
}

/*
*fin ajout*
*/


// sauvegarde du résultat



ImageJpeg($im, $miniature);
echo '<div><img src="' . $miniature . '"></div>';
}
}
?>

<!doctype html>
<html>
<head>


<meta charset="utf-8">
<title>Document sans titre</title>
</head>

<body onload="javascript:">
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="verify.php"">
<input name="captcha" type="text" id="captcha" value="" >
<input name="captchatxt" type="hidden" id="captchatxt" value="<?php echo $capt; ?>" >
<input type="submit" name="Submit" id="submit" value="Envoyer">

</form>
<form method="post" name="form1" id="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>"><input type="submit" name="recapt" value="recaptcha">
</form>
</body>
</html>
cs_remib74 Messages postés 15 Date d'inscription vendredi 10 août 2007 Statut Membre Dernière intervention 5 mars 2020
27 juil. 2014 à 12:08
Vous pouvez tester le formulaire ici :
http://codingandscripting.comli.com/_code/
Rejoignez-nous