Accueil > > > WAVY CAPTCHA
WAVY CAPTCHA
Information sur la source
Description
Encore un captcha. Pour celui-ci, je ne me suis pas vraiment foulé ;-) J'ai pris la base du code de Coockiesch : http://www.phpcs.com/codes/IMAGE-ANTI-SPAM_38969.a spx et l'algorithme de la classe Kaptcha de Kruglov Sergei : http://www.phpclasses.org/browse/package/3193.html pour les vagues. L'utilisation est comme d'hab : on définit les variables au début du fichier pour personnaliser. On récupère dans la variable de session $_SESSION['captcha'] la chaîne. Voilà :-)
Source
- <?php
- /**
- * Wavy Captcha
- * @author : Johan Barbier <johan.barbier@gmail.com>
- * Original idea and code from Coockiesch : http://www.phpcs.com/codes/IMAGE-ANTI-SPAM_38969.aspx
- * Algorithm for wavy stuff from Kruglov Sergei : http://www.phpclasses.org/browse/package/3193.html
- * I just mixed both, basically
- */
- // definitions
- $foreground_color = array(mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
- $background_color = array(mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
-
- $strlen = 5;
-
- $width = $strlen * 30 + 20;
- $height = 60;
-
- $iLinesAndArcs = 10;
-
- $iFontMax = 20;
- $iFontMin = 25;
- $iFontRotationMin = -30;
- $iFontRotationMax = 30;
- $iFontBaseLine = $height - 15;
- $iFontSpace = 20;
- $iFontMult = 30;
-
- $rMin = 180;
- $rMax = 255;
- $vMin = 180;
- $vMax = 255;
- $bMin = 180;
- $bMax = 255;
-
- $sTTFFontPath = 'verdana.ttf';
-
- // création
- $img = imagecreatetruecolor($width, $height);
- $img2 = imagecreatetruecolor($width, $height);
- imageantialias( $img, 1 );
-
- $foreground = imagecolorallocate($img, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
- $background = imagecolorallocate($img, $background_color[0], $background_color[1], $background_color[2]);
-
- imagefill ($img, 0,0,$background);
-
- $rand1=mt_rand(900000,1000000)/10000000;
- $rand2=mt_rand(900000,1000000)/10000000;
- $rand3=mt_rand(900000,1000000)/10000000;
- $rand4=mt_rand(900000,1000000)/10000000;
- // phases
- $rand5=mt_rand(0,3141592)/500000;
- $rand6=mt_rand(0,3141592)/500000;
- $rand7=mt_rand(0,3141592)/500000;
- $rand8=mt_rand(0,3141592)/500000;
- // amplitudes
- $rand9=mt_rand(330,420)/110;
- $rand10=mt_rand(330,450)/110;
-
- for( $i = 0; $i < $iLinesAndArcs; $i++ ) {
- $r = mt_rand ($rMin, $rMax);
- $v = mt_rand ($vMin, $vMax);
- $b = mt_rand ($bMin, $bMax);
- $color = imagecolorallocate($img, $r, $v, $b);
- imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $color);
- imagearc($img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), 0, 360, $color);
- }
-
- // chaine
- $string = 'ABCDEFGHIJKLMNPQRSTUVWXYZ23456789';
- $chaine = '';
- for( $i = 0; $i < $strlen; $i++ )
- $chaine .= $string[ mt_rand( 0, strlen ($string) - 1 ) ];
-
- $_SESSION['test'] = $chaine;
-
- for( $i = 0; $i < $strlen; $i++ ) {
- imagettftext( $img, mt_rand($iFontMax, $iFontMin), mt_rand($iFontRotationMin, $iFontRotationMax), $i * $iFontMult + $iFontSpace, $iFontBaseLine, $foreground, $sTTFFontPath, $chaine[$i] );
- }
-
- //wavy stuff
- for($x=0;$x<$width;$x++){
- for($y=0;$y<$height;$y++){
- $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+($width/2)+1;
- $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;
-
- if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){
- $color=255;
- $color_x=255;
- $color_y=255;
- $color_xy=255;
- }else{
- $color=imagecolorat($img, $sx, $sy) & 0xFF;
- $color_x=imagecolorat($img, $sx+1, $sy) & 0xFF;
- $color_y=imagecolorat($img, $sx, $sy+1) & 0xFF;
- $color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF;
- }
-
- if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){
- $newred=$foreground_color[0];
- $newgreen=$foreground_color[1];
- $newblue=$foreground_color[2];
- }else if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){
- $newred=$background_color[0];
- $newgreen=$background_color[1];
- $newblue=$background_color[2];
- }else{
- $frsx=$sx-floor($sx);
- $frsy=$sy-floor($sy);
- $frsx1=1-$frsx;
- $frsy1=1-$frsy;
-
- $newcolor=(
- $color*$frsx1*$frsy1+
- $color_x*$frsx*$frsy1+
- $color_y*$frsx1*$frsy+
- $color_xy*$frsx*$frsy);
-
- if($newcolor>255) $newcolor=255;
- $newcolor=$newcolor/255;
- $newcolor0=1-$newcolor;
-
-
- $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
- $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
- $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
- }
-
- imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
- }
- }
-
-
- // bordure
- $noir = imagecolorallocate ($img2,0,0,0);
- imageline( $img2, 0, 0, $width, 0, $noir );
- imageline( $img2, 0, $height - 1, $width, $height - 1, $noir );
- imageline( $img2, 0, 0, 0, $height, $noir );
- imageline( $img2, $width - 1, 0, $width - 1, $height, $noir );
-
-
- // header: image
- header("Content-type: image/png");
- imagepng( $img2 );
- imagedestroy( $img2 );
-
- ?>
<?php
/**
* Wavy Captcha
* @author : Johan Barbier <johan.barbier@gmail.com>
* Original idea and code from Coockiesch : http://www.phpcs.com/codes/IMAGE-ANTI-SPAM_38969.aspx
* Algorithm for wavy stuff from Kruglov Sergei : http://www.phpclasses.org/browse/package/3193.html
* I just mixed both, basically
*/
// definitions
$foreground_color = array(mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
$background_color = array(mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
$strlen = 5;
$width = $strlen * 30 + 20;
$height = 60;
$iLinesAndArcs = 10;
$iFontMax = 20;
$iFontMin = 25;
$iFontRotationMin = -30;
$iFontRotationMax = 30;
$iFontBaseLine = $height - 15;
$iFontSpace = 20;
$iFontMult = 30;
$rMin = 180;
$rMax = 255;
$vMin = 180;
$vMax = 255;
$bMin = 180;
$bMax = 255;
$sTTFFontPath = 'verdana.ttf';
// création
$img = imagecreatetruecolor($width, $height);
$img2 = imagecreatetruecolor($width, $height);
imageantialias( $img, 1 );
$foreground = imagecolorallocate($img, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
$background = imagecolorallocate($img, $background_color[0], $background_color[1], $background_color[2]);
imagefill ($img, 0,0,$background);
$rand1=mt_rand(900000,1000000)/10000000;
$rand2=mt_rand(900000,1000000)/10000000;
$rand3=mt_rand(900000,1000000)/10000000;
$rand4=mt_rand(900000,1000000)/10000000;
// phases
$rand5=mt_rand(0,3141592)/500000;
$rand6=mt_rand(0,3141592)/500000;
$rand7=mt_rand(0,3141592)/500000;
$rand8=mt_rand(0,3141592)/500000;
// amplitudes
$rand9=mt_rand(330,420)/110;
$rand10=mt_rand(330,450)/110;
for( $i = 0; $i < $iLinesAndArcs; $i++ ) {
$r = mt_rand ($rMin, $rMax);
$v = mt_rand ($vMin, $vMax);
$b = mt_rand ($bMin, $bMax);
$color = imagecolorallocate($img, $r, $v, $b);
imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $color);
imagearc($img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), 0, 360, $color);
}
// chaine
$string = 'ABCDEFGHIJKLMNPQRSTUVWXYZ23456789';
$chaine = '';
for( $i = 0; $i < $strlen; $i++ )
$chaine .= $string[ mt_rand( 0, strlen ($string) - 1 ) ];
$_SESSION['test'] = $chaine;
for( $i = 0; $i < $strlen; $i++ ) {
imagettftext( $img, mt_rand($iFontMax, $iFontMin), mt_rand($iFontRotationMin, $iFontRotationMax), $i * $iFontMult + $iFontSpace, $iFontBaseLine, $foreground, $sTTFFontPath, $chaine[$i] );
}
//wavy stuff
for($x=0;$x<$width;$x++){
for($y=0;$y<$height;$y++){
$sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+($width/2)+1;
$sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;
if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){
$color=255;
$color_x=255;
$color_y=255;
$color_xy=255;
}else{
$color=imagecolorat($img, $sx, $sy) & 0xFF;
$color_x=imagecolorat($img, $sx+1, $sy) & 0xFF;
$color_y=imagecolorat($img, $sx, $sy+1) & 0xFF;
$color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF;
}
if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){
$newred=$foreground_color[0];
$newgreen=$foreground_color[1];
$newblue=$foreground_color[2];
}else if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){
$newred=$background_color[0];
$newgreen=$background_color[1];
$newblue=$background_color[2];
}else{
$frsx=$sx-floor($sx);
$frsy=$sy-floor($sy);
$frsx1=1-$frsx;
$frsy1=1-$frsy;
$newcolor=(
$color*$frsx1*$frsy1+
$color_x*$frsx*$frsy1+
$color_y*$frsx1*$frsy+
$color_xy*$frsx*$frsy);
if($newcolor>255) $newcolor=255;
$newcolor=$newcolor/255;
$newcolor0=1-$newcolor;
$newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
$newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
$newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
}
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
}
}
// bordure
$noir = imagecolorallocate ($img2,0,0,0);
imageline( $img2, 0, 0, $width, 0, $noir );
imageline( $img2, 0, $height - 1, $width, $height - 1, $noir );
imageline( $img2, 0, 0, 0, $height, $noir );
imageline( $img2, $width - 1, 0, $width - 1, $height, $noir );
// header: image
header("Content-type: image/png");
imagepng( $img2 );
imagedestroy( $img2 );
?>
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Souci formulaire contact php avec captcha [ par snip74 ]
Bonjour, je fait appel a vous car je pète un câble lol. Voila j'ai trouvé un système de captcha je les mis sur mon formulaire de contact et rien ne
formulaire php htlm / captcha [ par djbabou ]
Bonjour, a tous J'ai développé un formulaire dans lequel j'ai intégrer un captcha image. Comme tous captcha normalement construit, après soumission d
Authentification php [ par rems675 ]
Bonsoir, J'ai un énorme problème et je comprend pas, ou plus du tout, j'ai tenté des millier de chose mais rien à faire. Cela concerne une authentific
problème Formulaire(select)?? [ par minoula2006 ]
Bonjour, J'aimerai bien que vous m'aider à résoudre mon problème, je programme en PHP un formulaire ou je doit ajouter une actualité qui utilise un t
formulaire dynamique php ,sqlserver [ par hantouva ]
bonjour; voila je fais un site web dynamique en php et jutilise une base de donnees sql server je bloque au niveau du formulaire de recherche qui do
Perte de session avec ie ??? [ par gfpl ]
Bon voila le souci je peut le tourner comme je veut mais je ne trouve pas la solution .... j'essaie en vain mais non... la session marche avec chrome
Garder les valeurs de mes tableaux quand je rafaraichit ma page [ par Varkan ]
Bonjour à tous ! Je fais actuellement mon Memory, avec différentes tableaux en php qui contiennent des numéros aléatoires et avec cela je met mes ima
Architecture d'un formulaire client + divers fonctions (email, macros....). [ par quinton75 ]
Bonjour, J'ai créée un formulaire pour demander aux clients smart box de renseigner leurs infos persos ....En bas de page, le code..... Et j'aimera
Formulaire et variable vide [ par WrestlingMan ]
Bonjour à tous, je vais essayer d'être clair. J'ai mis un site en ligne il y a à peu près 2 à 3 mois, après avoir fait tout les tests nécessaire bien
envoyer le contenu du formulaire vers un mail [ par hamzvb ]
bonjour; je suis en train de créer un site web et j'ai un formulaire de contact que je veux que son contenu sera envoyé à mon adresse mail au fur et a
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : SONDAGE..RE : SONDAGE.. par phpAnonyme
Cliquez pour lire la suite par phpAnonyme RE : SONDAGE..RE : SONDAGE.. par TychoBrahe
Cliquez pour lire la suite par TychoBrahe
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|