PageRenderTime 35ms CodeModel.GetById 27ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/membres/captcha.php

https://github.com/FannyCayzeele/examen-de-php
PHP | 139 lines | 70 code | 18 blank | 51 comment | 0 complexity | 43650de7a2a864069d223c2848c3f4d3 MD5 | raw file
  1<?php
  2/*
  3Neoterranos & LkY
  4Page captcha.php
  5
  6Génère un captcha.
  7
  8Quelques indications : (utiliser l'outil de recherche et rechercher les mentions données)
  9
 10Liste des fonctions :
 11--------------------------
 12Aucune fonction
 13--------------------------
 14
 15
 16Liste des informations/erreurs :
 17--------------------------
 18Aucune information/erreur
 19--------------------------
 20*/
 21
 22session_start();
 23header ("Content-type: image/png");
 24$image = imagecreate(320, 100);
 25
 26$blanc = imagecolorallocate($image, 255, 255, 255);
 27$noir = imagecolorallocate($image, 0, 0, 0);
 28$gris = imagecolorallocate($image, 200,200,200);
 29$jaune = imagecolorallocate($image, 255, 255, 0);
 30$rouge = imagecolorallocate($image, 200, 39, 45);
 31$vert = imagecolorallocate($image, 45, 255, 39);
 32$cyan = imagecolorallocate($image, 0, 255, 255);
 33$magenta = imagecolorallocate($image, 200, 0, 200);
 34$orange = imagecolorallocate($image, 255, 160, 0);
 35$bleu = imagecolorallocate($image, 60, 75, 200);
 36$bleuclair = imagecolorallocate($image, 156, 227, 254);
 37$vertf = imagecolorallocate($image, 20, 140, 17);
 38
 39/*$Anoir = imagecolorallocatealpha($image, 0, 0, 0, 80);
 40$Ajaune = imagecolorallocatealpha($image, 255, 255, 0, 80);
 41$Ablanc = imagecolorallocatealpha($image, 255, 255, 255, 80);
 42$Arouge = imagecolorallocatealpha($image, 200, 39, 45, 80);
 43$Avert = imagecolorallocatealpha($image, 45, 200, 39, 80);
 44$Acyan = imagecolorallocatealpha($image, 0, 255, 255, 80);
 45$Amagenta = imagecolorallocatealpha($image, 255, 0, 255, 80);
 46$Aorange = imagecolorallocatealpha($image, 255, 128, 0, 80);
 47$Ableu = imagecolorallocatealpha($image, 39, 45, 200, 80);
 48$Ableuclair = imagecolorallocatealpha($image, 156, 227, 254, 80);
 49
 50$A2noir = imagecolorallocatealpha($image, 0, 0, 0, 25);
 51$A2jaune = imagecolorallocatealpha($image, 255, 255, 0, 25);
 52$A2blanc = imagecolorallocatealpha($image, 255, 255, 255, 25);
 53$A2rouge = imagecolorallocatealpha($image, 200, 39, 45, 25);
 54$A2vert = imagecolorallocatealpha($image, 45, 200, 39, 25);
 55$A2cyan = imagecolorallocatealpha($image, 0, 255, 255, 25);
 56$A2magenta = imagecolorallocatealpha($image, 255, 0, 255, 25);
 57$A2orange = imagecolorallocatealpha($image, 255, 128, 0, 25);
 58$A2bleu = imagecolorallocatealpha($image, 39, 45, 200, 25);
 59$A2bleuclair = imagecolorallocatealpha($image, 156, 227, 254, 25);*/
 60
 61//Toutes les couleurs
 62$colors = Array($vert, $noir, $jaune, $blanc, $rouge, $cyan, $magenta, $orange, $bleu, $bleuclair, $gris, $vertf);
 63$Tcolors = count($colors);
 64
 65/*$colors2 = Array($Avert, $Anoir, $Ajaune, $Ablanc, $Arouge, $Acyan, $Amagenta, $Aorange, $Ableu, $Ableuclair);
 66$Tcolors2 = count($colors2);
 67$colors3 = Array($A2vert, $A2noir, $A2jaune, $A2blanc, $A2rouge, $A2cyan, $A2magenta, $A2orange, $A2bleu, $A2bleuclair);
 68$Tcolors3 = count($colors3);*/
 69
 70//couleurs autorisées pour les caractères
 71$Lcolors = Array($noir, $rouge, $magenta, $bleu, $vertf);
 72$TLcolors = count($Lcolors);
 73
 74$polices = Array('helvetica'); //Pensez à en rajouter !!
 75$Tpolices = count($polices);
 76
 77//définition des caractères autorisés.
 78$carac = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 79$Tcarac = strlen($carac);
 80
 81//définition des lignes noires
 82$nb_lignes = mt_rand(3,7);
 83$i = 1;
 84while($i<=$nb_lignes)
 85{
 86	ImageLine($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280, 320), mt_rand(0,100), $noir);
 87	$i++;
 88}
 89
 90//définition des lignes colorées.
 91$nb_lignes = mt_rand(3,7);
 92$i = 1;
 93while($i<=$nb_lignes)
 94{
 95	ImageLine($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280,320), mt_rand(0,100), $colors[mt_rand(0,$Tcolors-1)]);
 96	$i++;
 97}
 98
 99//définition des ellipses
100$nb_ellipses = mt_rand(1,6);
101$i = 1;
102while($i<= $nb_ellipses)
103{
104	ImageEllipse($image, mt_rand(0,320), mt_rand(0,100), 25+mt_rand(0,15), 25+mt_rand(0,15), $colors[mt_rand(0,$Tcolors-1)]);
105	$i++;
106}
107
108//définition des triangles
109$nb_triangles = mt_rand(1,6);
110$i = 1;
111while($i<=$nb_triangles)
112{
113	$array = Array(mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100));
114	ImagePolygon($image, $array, 3, $colors[mt_rand(0,$Tcolors-1)]);
115	$i++;
116}
117
118
119$aupifcolor = $Lcolors[mt_rand(0,$TLcolors-1)]; //la couleur des caractères
120$ecart = 300/10+4; //écart entre les caractères
121
122$_SESSION['captcha'] = ''; //La voilà !! Enfin !!
123
124$i = 0;
125while($i <= 7)
126{
127	$lettre = $carac[mt_rand(0, $Tcarac-1)]; //choix de lettre
128	$_SESSION['captcha'] .= $lettre; //stockage
129	$taille = mt_rand(35,45); //taille
130	$angle = mt_rand(-35,35); //angle
131	$y = mt_rand(55, 60); //ordonnée
132	$police = $polices[mt_rand(0, $Tpolices-1)]; //police :p
133	
134	imagettftext($image, $taille, $angle, $ecart*$i+15, $y, $aupifcolor, 'polices/'.$police.'.ttf', $lettre);
135	$i++;
136}
137
138imagepng($image); //On envoie et on prie :p
139?>