|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
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
Sources de la même categorie
Sources en rapport avec celle ci
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
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|