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