Vous êtes ici Codes PHP et MySQL > Formulaires > Image anti spam V2

 

Image anti spam V2

La deuxième version de mon image anti spam pour protéger vos formulaire!
Utilisation: Voir le code, tout est écrit !!!
 
R@f
[17] sources en PHP voir
Code vu 7756 fois
Enregistré le 08 Sept 2007
  • Digg ce code sur digg.com
  • Bookmark ce code sur del.icio.us
  • Bookmark ce code sur Google
  • Bookmark ce code sur Yahoo
  • Ajoute Image anti spam V2
  • Partage ce code sur Facebook
 
 
 
 

Code Source


01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
 
<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Image anti spam V2                                        */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts300-PHP.htm              */
/* Auteur         : R@f                                                       */
/* Date édition   : 08 Sept 2007                                              */
/*                                                                            */
/******************************************************************************/
?>
 >> le contenu dans l'image sera dans $_SESSION['livreor']
 >> 4 caractères

 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" />

 Si $spam représente l'entrée utilsateur, le test se fait comme ceci:
 if( $_SESSION['livreor'] != strtoupper( $spam ) )
// erreur ici


<?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 bo! :-)
imageantialias$img);

// chaine
$string 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chaine '';
for( $i = ; $i $strlen$i++ )
  $chaine .= $stringmt_rand( , 35 ) ];
  
$_SESSION$name ] = $chaine;

// couleur de départ
$c1 = array( mt_rand200255), mt_rand200255), mt_rand200255) );
// couleur finale
$c2 = array( mt_rand70180), mt_rand70180), mt_rand70180) );
// pas pour chaque composante de couleur
$diffsColor = array( ( $c1[] - $c2[] ) / $widthColor, ( $c1[1] - $c2[1] ) / 
$widthColor, ( $c1[2] - $c2[2] ) / $widthColor );

$start = ;
$end $widthColor;

for( $j = ; $j 4$j++ ) // boucle pour chacune des 4 zones
{
  $r $j ==  ? $c1[] : $c2[]; // composante r de d?part
  $v $j ==  ? $c1[1] : $c2[1]; // idem v
  $b $j ==  ? $c1[2] : $c2[2]; // idem b
  
  // création des lignes
  for( $i $start$i $end$i++ )
  {
    if( $j ==  )
    {
      $r -= $diffsColor[];
      $v -= $diffsColor[1];
      $b -= $diffsColor[2];
    }
    else
    {
      $r += $diffsColor[];
      $v += $diffsColor[1];
      $b += $diffsColor[2];
    }
    
    $color imagecolorallocate$img$r$v$b );
    
    imageline$img$i, , $i$height$color );
  }
  
  $start += $widthColor;
  $end += $widthColor;
}

$colorsChar = array( ); // on va mémoriser les couleurs des caractères

// caractères
for( $i = ; $i $strlen$i++ )
{
  $colorsChar[$i] = imagecolorallocate$imgmt_rand( , 120 ), mt_rand( , 120 )
, mt_rand( , 120 ) );
  imagettftext$imgmt_rand2025 ), mt_rand( -3535 ), 10 $i 2335$colorsChar[$i], 'comic.ttf'$chaine$i ] );
}

// quelques lignes qui embetent
for( $i = ; $i 10$i++ )
{
  imageline$imgmt_rand(, $width), mt_rand(, $height), mt_rand(, $width), 
mt_rand(, $height), $colorsChar[mt_rand( , $strlen )] );
}

$noir imagecolorallocate$img, , ,  );

// bordure
imageline$img, , , $width, , $noir );
imageline$img, , , , $height$noir );
imageline$img$width 1, , $width 1$height$noir );

// header: image
header("Content-type: image/png");
imagepng$img ); 
imagedestroy$img );
?>

 

Fonctions du code

: Initialise une session - (PHP 4, PHP 5)
: Crée une nouvelle image en couleurs vraies - (PHP 4 >= 4.0.6, PHP 5)
: Utiliser ou non les fonctions d'antialias - (PHP 4 >= 4.3.2, PHP 5)
: Génère une meilleure valeur aléatoire - (PHP 4, PHP 5)
: Crée un tableau - (PHP 4, PHP 5)
: Alloue une couleur pour une image - (PHP 4, PHP 5)
: Dessine une ligne - (PHP 4, PHP 5)
: Dessine un texte avec une police TrueType - (PHP 4, PHP 5)
: Envoie un en-tête HTTP - (PHP 4, PHP 5)
: Envoie une image PNG vers un navigateur ou un fichier - (PHP 4, PHP 5)
: Détruit une image - (PHP 4, PHP 5)
Commentaires
SAlut R@f,

tout d'abord un grand merci pour avoir pris la peine d'écrire et de déposer ce script sur phpsources.org.

J'ai essayé de le faire fonctionner chez moi mais je n'arrive pas à le faire fonctionner.

En effet, j'ai copié le code dans un fichier appelé script_anti_spam.php et modifié l'adresse de l'image en conséquence. J'ai mis l'adresse de l'image anti spam dans mon formulaire (celui d'inscription des utilisateurs) mais rien ne se passe ?!

Pire encore, lorsque je lance ton script dans mozilla, j'ai le message suivant :

L'image "blah blah" ne peut etre affichée car elle contient des erreurs.

Avant de noter ton script, j'aimerais le faire fonctionner pour voir s'il marche.

MErci à toi!

Pierre75000
 
Moi je l'ai essayé, et ça marchait nickel sur mon poste, une fois j'ai mis le site sur le serveur ça marche plus??

pour toi pierre, est ce que t'a insérer le comic.ttf dans la racine, sinon ça marchera pas.

wazou
 
J'ai essayé le code également en prenant soin de créer un fichier

anti-spam.php  dans l'image inserrer dans le formulaire et en ajoutant la typo comic.ttf  à la racine mais rien ne marche.......... y a t-il une solution?
 
Ajouter un commentaire
Code de sécurité

Attention: Les champs marqués d'une étoile * sont obligatoires
 
Librairie PHP

Connexion

 
 

Formulaires

 
 

PHP

 
 
 
 
    Offres d'emploi

Plus de 500 offres d'emploi PHP/MySQL

Offres d'emploi
 
    Editeur PHP
 
        Publicité