Accueil > > > IMAGE ANTI-SPAM
IMAGE ANTI-SPAM
Information sur la source
Description
Un petit script tout simple qui crée une image anti-spam... Deux versions (correspondant aux deux zones de la capture): - une simple (mais plus facilement lisible par des scripts OCR) - et la seconde ben... moins lisibles (pour les gens comme pour les robots, ^^) Dans le cas d'une utilisation de la seconde version, il serait pas mal de remplir le formulaire avec les valeurs déjà entrées en cas d'erreur de code car ca risque de se produire (on peut aussi enlenver le 0, le O et le D des caractères disponibles).
Source
- <?php
- session_start();
-
- // type de flood
- $name = $_GET['name'];
- // nb de caractères
- $strlen = (int) $_GET['strlen'];
-
- // taille de l'image ( width )
- $width = $strlen * 30 + 20;
- $height = 60;
-
- // création
- $img = imagecreatetruecolor( $width, $height );
- // antialising, c'est plus bô! :-)
- imageantialias( $img, 1 );
-
- // chaine
- $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $chaine = '';
- for( $i = 0; $i < $strlen; $i++ )
- $chaine .= $string[ mt_rand( 0, 35 ) ];
-
- $_SESSION[ $name ] = $chaine;
-
- // couleur de départ
- $c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
- // couleur finale
- $c2 = array( mt_rand( 150, 200), mt_rand( 150, 200), mt_rand( 150, 200) );
-
- $colors = array( imagecolorallocate( $img, 70, 130, 255 ) , imagecolorallocate( $img, 255, 237, 175 ), imagecolorallocate( $img, 166, 250, 186 ), imagecolorallocate( $img, 253, 188, 251 ), imagecolorallocate( $img, 255, 255, 255 ) );
-
- // création de l'image
- for( $i = 0; $i < $width; $i++ )
- {
- $r = $c1[0] + $i * ( $c2[0] - $c1[0] ) / $width;
- $v = $c1[1] + $i * ( $c2[1] - $c1[1] ) / $width;
- $b = $c1[2] + $i * ( $c2[2] - $c1[2] ) / $width;
- $color = imagecolorallocate( $img, $r, $v, $b );
-
- imageline( $img, $i, 0, $i, $height, $color );
- }
-
- // caractères
- for( $i = 0; $i < $strlen; $i++ )
- {
- $col = imagecolorallocate( $img, mt_rand( 0, 120 ), mt_rand( 0, 120 ), mt_rand( 0, 120 ) );
- imagettftext( $img, mt_rand( 20, 25 ), mt_rand( -30, 30 ), 10 + $i * 30, 35, $col, 'comic.ttf', $chaine[ $i ] );
- }
-
- // quelques lignes qui embêtent
- for( $i = 0; $i < 8; $i++ )
- {
- imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colors[mt_rand( 0, 4 )] );
- }
-
- $noir = imagecolorallocate( $img, 0, 0, 0 );
-
- // bordure
- imageline( $img, 0, 0, $width, 0, $noir );
- imageline( $img, 0, 0, 0, $height, $noir );
- imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
-
- // header: image
- header("Content-type: image/png");
- imagepng( $img );
- imagedestroy( $img );
- ?>
-
- ########################################################################
- Seconde version:
- <?php
- session_start();
-
- // type de flood
- $name = $_GET['name'];
- // nb de caractères
- $strlen = (int) $_GET['strlen'];
-
- // taille de l'image ( width )
- $width = $strlen * 23 + 20;
- $height = 60;
- // taille de chaque zone de couleur
- $widthColor = $width / 4;
-
- // création
- $img = imagecreatetruecolor( $width, $height );
- // antialising, c'est plus bô! :-)
- imageantialias( $img, 1 );
-
- // chaine
- $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $chaine = '';
- for( $i = 0; $i < $strlen; $i++ )
- $chaine .= $string[ mt_rand( 0, 35 ) ];
-
- $_SESSION[ $name ] = $chaine;
-
- // couleur de départ
- $c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
- // couleur finale
- $c2 = array( mt_rand( 70, 180), mt_rand( 70, 180), mt_rand( 70, 180) );
- // pas pour chaque composante de couleur
- $diffsColor = array( ( $c1[0] - $c2[0] ) / $widthColor, ( $c1[1] - $c2[1] ) / $widthColor, ( $c1[2] - $c2[2] ) / $widthColor );
-
- $start = 0;
- $end = $widthColor;
-
- for( $j = 0; $j < 4; $j++ ) // boucle pour chacune des 4 zones
- {
- $r = $j % 2 == 0 ? $c1[0] : $c2[0]; // composante r de départ
- $v = $j % 2 == 0 ? $c1[1] : $c2[1]; // idem v
- $b = $j % 2 == 0 ? $c1[2] : $c2[2]; // idem b
-
- // création des lignes
- for( $i = $start; $i < $end; $i++ )
- {
- if( $j % 2 == 0 )
- {
- $r -= $diffsColor[0];
- $v -= $diffsColor[1];
- $b -= $diffsColor[2];
- }
- else
- {
- $r += $diffsColor[0];
- $v += $diffsColor[1];
- $b += $diffsColor[2];
- }
-
- $color = imagecolorallocate( $img, $r, $v, $b );
-
- imageline( $img, $i, 0, $i, $height, $color );
- }
-
- $start += $widthColor;
- $end += $widthColor;
- }
-
- $colorsChar = array(); // on va mémoriser les couleurs des caractères
-
- // caractères
- for( $i = 0; $i < $strlen; $i++ )
- {
- $colorsChar[$i] = imagecolorallocate( $img, mt_rand( 0, 120 ), mt_rand( 0, 120 ), mt_rand( 0, 120 ) );
- imagettftext( $img, mt_rand( 20, 25 ), mt_rand( -35, 35 ), 10 + $i * 23, 35, $colorsChar[$i], 'comic.ttf', $chaine[ $i ] );
- }
-
- // quelques lignes qui embêtent
- for( $i = 0; $i < 10; $i++ )
- {
- imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colorsChar[mt_rand( 0, $strlen - 1 )] );
- }
-
- $noir = imagecolorallocate( $img, 0, 0, 0 );
-
- // bordure
- imageline( $img, 0, 0, $width, 0, $noir );
- imageline( $img, 0, 0, 0, $height, $noir );
- imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
-
- // header: image
- header("Content-type: image/png");
- imagepng( $img );
- imagedestroy( $img );
- ?>
<?php
session_start();
// type de flood
$name = $_GET['name'];
// nb de caractères
$strlen = (int) $_GET['strlen'];
// taille de l'image ( width )
$width = $strlen * 30 + 20;
$height = 60;
// création
$img = imagecreatetruecolor( $width, $height );
// antialising, c'est plus bô! :-)
imageantialias( $img, 1 );
// chaine
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chaine = '';
for( $i = 0; $i < $strlen; $i++ )
$chaine .= $string[ mt_rand( 0, 35 ) ];
$_SESSION[ $name ] = $chaine;
// couleur de départ
$c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
// couleur finale
$c2 = array( mt_rand( 150, 200), mt_rand( 150, 200), mt_rand( 150, 200) );
$colors = array( imagecolorallocate( $img, 70, 130, 255 ) , imagecolorallocate( $img, 255, 237, 175 ), imagecolorallocate( $img, 166, 250, 186 ), imagecolorallocate( $img, 253, 188, 251 ), imagecolorallocate( $img, 255, 255, 255 ) );
// création de l'image
for( $i = 0; $i < $width; $i++ )
{
$r = $c1[0] + $i * ( $c2[0] - $c1[0] ) / $width;
$v = $c1[1] + $i * ( $c2[1] - $c1[1] ) / $width;
$b = $c1[2] + $i * ( $c2[2] - $c1[2] ) / $width;
$color = imagecolorallocate( $img, $r, $v, $b );
imageline( $img, $i, 0, $i, $height, $color );
}
// caractères
for( $i = 0; $i < $strlen; $i++ )
{
$col = imagecolorallocate( $img, mt_rand( 0, 120 ), mt_rand( 0, 120 ), mt_rand( 0, 120 ) );
imagettftext( $img, mt_rand( 20, 25 ), mt_rand( -30, 30 ), 10 + $i * 30, 35, $col, 'comic.ttf', $chaine[ $i ] );
}
// quelques lignes qui embêtent
for( $i = 0; $i < 8; $i++ )
{
imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colors[mt_rand( 0, 4 )] );
}
$noir = imagecolorallocate( $img, 0, 0, 0 );
// bordure
imageline( $img, 0, 0, $width, 0, $noir );
imageline( $img, 0, 0, 0, $height, $noir );
imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
// header: image
header("Content-type: image/png");
imagepng( $img );
imagedestroy( $img );
?>
########################################################################
Seconde version:
<?php
session_start();
// type de flood
$name = $_GET['name'];
// nb de caractères
$strlen = (int) $_GET['strlen'];
// taille de l'image ( width )
$width = $strlen * 23 + 20;
$height = 60;
// taille de chaque zone de couleur
$widthColor = $width / 4;
// création
$img = imagecreatetruecolor( $width, $height );
// antialising, c'est plus bô! :-)
imageantialias( $img, 1 );
// chaine
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chaine = '';
for( $i = 0; $i < $strlen; $i++ )
$chaine .= $string[ mt_rand( 0, 35 ) ];
$_SESSION[ $name ] = $chaine;
// couleur de départ
$c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
// couleur finale
$c2 = array( mt_rand( 70, 180), mt_rand( 70, 180), mt_rand( 70, 180) );
// pas pour chaque composante de couleur
$diffsColor = array( ( $c1[0] - $c2[0] ) / $widthColor, ( $c1[1] - $c2[1] ) / $widthColor, ( $c1[2] - $c2[2] ) / $widthColor );
$start = 0;
$end = $widthColor;
for( $j = 0; $j < 4; $j++ ) // boucle pour chacune des 4 zones
{
$r = $j % 2 == 0 ? $c1[0] : $c2[0]; // composante r de départ
$v = $j % 2 == 0 ? $c1[1] : $c2[1]; // idem v
$b = $j % 2 == 0 ? $c1[2] : $c2[2]; // idem b
// création des lignes
for( $i = $start; $i < $end; $i++ )
{
if( $j % 2 == 0 )
{
$r -= $diffsColor[0];
$v -= $diffsColor[1];
$b -= $diffsColor[2];
}
else
{
$r += $diffsColor[0];
$v += $diffsColor[1];
$b += $diffsColor[2];
}
$color = imagecolorallocate( $img, $r, $v, $b );
imageline( $img, $i, 0, $i, $height, $color );
}
$start += $widthColor;
$end += $widthColor;
}
$colorsChar = array(); // on va mémoriser les couleurs des caractères
// caractères
for( $i = 0; $i < $strlen; $i++ )
{
$colorsChar[$i] = imagecolorallocate( $img, mt_rand( 0, 120 ), mt_rand( 0, 120 ), mt_rand( 0, 120 ) );
imagettftext( $img, mt_rand( 20, 25 ), mt_rand( -35, 35 ), 10 + $i * 23, 35, $colorsChar[$i], 'comic.ttf', $chaine[ $i ] );
}
// quelques lignes qui embêtent
for( $i = 0; $i < 10; $i++ )
{
imageline( $img, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colorsChar[mt_rand( 0, $strlen - 1 )] );
}
$noir = imagecolorallocate( $img, 0, 0, 0 );
// bordure
imageline( $img, 0, 0, $width, 0, $noir );
imageline( $img, 0, 0, 0, $height, $noir );
imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
// header: image
header("Content-type: image/png");
imagepng( $img );
imagedestroy( $img );
?>
Conclusion
Si le script est enregistré dans le fichier: anti_spam.php, on appèle l'image comme ceci:
<img src="anti_spam.php?name=livreor&strlen=4" alt="anti-flood" />
>> le contenu dans l'image sera dans $_SESSION['livreor'] >> 4 caractères
Si $spam représente l'entrée utilsateur, le test se fait comme ceci: if( $_SESSION['livreor'] != strtoupper( $spam ) ) // erreur ici
Voilà, j'attends vos comments sur ce petit script tout simple!
P.S. Ne pas oublier le session_start() sur la page qui vérifie les données! :-)
Historique
- 05 octobre 2006 16:19:05 :
- Ajout zip
- 16 avril 2007 20:20:38 :
- Complexification de l'image:
- rapprochement des lettres
- augmentation de la rotation
- augmentation du nombre de lignes
- les lignes sont de la même couleur que les caractères
- plage de couleurs du dégradé plus large (donc plus proche de la couleur des caractères)
- 4 dégradés au lieu d'un
- 22 janvier 2008 21:40:08 :
- Ajout d'une info
Sources du même auteur
GÉRER UN .HTPASSWDGÉRER UN .HTPASSWD Une mini source sans grande prétention: le but est de gérer un fichier .htpasswd de manière à ce que seuls les utilisateurs d'un site aient accès aux ...
RÉCUPÉRER L'IP DU VISITEURRÉCUPÉRER L'IP DU VISITEUR Suite à un commentaire sur un source je vous propose, ce code, qui n'est pas de moi, et qui permet de récupérer l'ip du visiteur.
Ces deux fonction...
MOTEUR DE RECHERCHE DANS BDD IIMOTEUR DE RECHERCHE DANS BDD II Voilà, une petite classe permettant de générer une requête de recherche pour une bdd.
J'ai déjà fait un code similaire ; la raison pour laquelle je n...
PRETTY DATEPRETTY DATE Pour commencer, l'idée de ce code et son implémentation ne sont pas de moi, il s'agit d'un code d'olid:
http://www.phpcs.com/codes/AFFICHER-DATE-HEUR...
FORMULAIRE (NEWS, LIVRE D'OR, ...)FORMULAIRE (NEWS, LIVRE D'OR, ...)Le zip contient le code pour faire un formulaire (pour un ajout de news, message dans livre d'or, etc).
Code HTML:
- formulaire en lui même
Cod...
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
:::::: URGENT !!! ENVOI D'IMAGE PAR FTP !!!! ERREUR :::::: [ par kkz_mil3k ]
j'essaie d'nevoyer un fichier image gif ou jpg sur un ftp via ce formulaire php :------------------------------------------- //**connecte au ftp sc
Comment insérer un champs image ds ma table ?? [ par inceV ]
Salut à tous et bonne année 2002 !!!Bon, je n'arrive pas à créer un champs 'image' ds ma table et je ne comprends pas tp commen ça marche, pourriez-vo
Faire unr image sur le serveur en PHP [ par fabiin ]
Salut !En ASP, il y a un composant ki permet de créer une image sur le serveur,...on peu avec 2-3 ligne de codes, faire un dégradé, mettre du texte, e
Insérer une image dans une autre [ par cduf ]
Je sais créer une image (compteur) avec des commandes php GD, mais comment l'insérer dans une autre (bannière). Merci de m'aider.Email : cdufetelle@wa
envoyer une image dans le $message de mail() [ par linov ]
Bonjour,Comment faire pour envoyer une image dans le $message envoyé par la fonction mail() ?Syntaxe ? Paramètres ? Est-ce possible ?Merci de votre ai
include image [ par erich10 ]
comment faire un include d'une image ?et comment faire en plus un lien sur cette image?merci
générer des miniatures avec gd 1.6 [ par vegetaline ]
muhaha alors là c'est rigolo, un super défi pour les programmeurs fous!ok j'ai le code pour générer des miniatures grâce au php, mais ça marche qu'ave
MySQL et images [ par Marneus Calgar ]
SalutJ'aimerais savoir s'il est possible de stocker des images dans une table MySQL et d'y accéder depuis une page PHP. En fait, je voudrais faire un
MySQL et images [ par Marneus Calgar ]
SalutJ'aimerais savoir s'il est possible de stocker des images dans une table MySQL et d'y accéder depuis une page PHP. En fait, je voudrais faire un
Ne pas afficher la barre de Menu Image [ par microdav ]
Bonjour à vous Internaute,je vous soumets une petite question...Je recherche Code permettant de ne pas faire afficher la barre de menu "Image" sur une
|
Derniers Blogs
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Logiciels
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 Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.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 LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|