Captcha anti-bot + fichier son (wav)

Description

Un captcha image assez robuste avec un générateur de fichier wav

La source jointe est la fonction de génération de l'image pour la génération du fichier son, c'est dans le zip.

La police angelina.ttf est disponible ici : http://www.dafont.com/fr/angelina.font et n'est pas incluse dans le zip. Il faut mettre le fichier ttf dans le même répertoire que le fichier captcha.php.

Il faut créer des fichiers wav qui prononce les nombres 0 1 2 3 4 5 6 7 8 9 dans le repertoire sounds. Je vous conseille le site : http://www.research.att.com/%7Ettsweb/tts/demo.php pour générer des fichiers wav. Vous devriez avoir les fichiers 0.wav, 1.wav etc...

Source / Exemple :


<?php
/** 
    Copyright (c) 2008
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

  • /
// Genere l'image session_start(); function nombre($n) { return str_pad(mt_rand(0,pow(10,$n)-1),$n,'0',STR_PAD_LEFT); } 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(-35,35); imagettftext($img,mt_rand($size-7,$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); imageconvolution($img, $matrix_blur,9,0); imagepng($img); imagedestroy($img); } function captcha() { $mot = nombre(5); $_SESSION['captcha'] = $mot; image($mot); } header("Content-type: image/png"); captcha(); ?>

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.