Guest User

Untitled

a guest
May 12th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <?php
  2.  
  3. $captcha_length = 6;
  4.  
  5. $image = imagecreatetruecolor ( 200, 75 );
  6.  
  7. $back_color = @ImageColorAllocate ( $image, 255, 255, 255 );
  8. $code = "";
  9. $inputCode = $_POST['captcha'];
  10.  
  11. for($i = 0; $i < $captcha_length; $i ++) {
  12.  
  13. $x_axis = 20 + ($i * 20);
  14. $y_axis = 50 + rand ( 0, 7 );
  15.  
  16. $color1 = rand ( 001, 150 );
  17. $color2 = rand ( 001, 150 );
  18. $color3 = rand ( 001, 150 );
  19. $txt_color [$i] = ImageColorAllocate ( $image, $color1, $color2, $color3 );
  20.  
  21. $size = rand ( 20, 30 );
  22.  
  23. $angle = rand ( -15, 15 );
  24.  
  25. $number = function ($len=1) {
  26. $s = "";
  27. $b="QWERTYUPASDFGHJKLZXCVBNMqwertyuopasdfghjkzxcvbnm123456789";
  28. while($len-->0) {
  29. $s.=$b[mt_rand(0,strlen($b))];
  30. }
  31. return "$s";
  32. };
  33. $t = $number();
  34. $code .= "$t";
  35.  
  36. imagettftext ( $image, $size, $angle, $x_axis, $y_axis, $txt_color[$i], "C:OSPaneldomainskultprosvetarial.ttf", $t);
  37. }
  38.  
  39. session_start();
  40.  
  41. $_SESSION ['captcha'] = $code;
  42.  
  43. header ( "Cache-Control: no-cache" );
  44.  
  45. header ( "Content-type: image/jpg" );
  46.  
  47. imagejpeg ( $image);
  48.  
  49. exit ();
  50.  
  51. <form id = "form">
  52. <input id = "name" type = "text" minlength="2" placeholder="Ваше имя" name = "name" required>
  53. <input id = "s_name" type = "text" placeholder="Ваша фамилия" name = "s_name" required>
  54. <input id = "email" type = "text" placeholder="email" name = "email" required>
  55. <select id = "ticket" required name = "ticket">
  56. <option>free</option>
  57. <option>standart</option>
  58. <option>premium</option>
  59. </select>
  60.  
  61. <img alt="" id="captcha" src="captcha.php" />
  62. <span onclick="document.getElementById('captcha').src=document.getElementById( 'captcha').src + '?' + Math.random();">обновить код</span>
  63. <input type="text" maxlength="<?=$captcha_length;?>" style="text-align: center;" autocomplete="off" name="captcha" value=""/>
  64.  
  65. <input id = "submit" type = "submit">
  66. </form>
  67.  
  68. <?php
  69. class Captcha
  70. {
  71.  
  72. public $captcha_length;
  73. public $image;
  74. public $back_color;
  75. public $code;
  76. public $inputCode;
  77.  
  78. function __construct(){
  79. parent::__construct();
  80. $this->captcha_length = 6;
  81. $this->image = imagecreatetruecolor (200, 75);
  82. $this->back_color = @ImageColorAllocate ($this->image, 255, 255, 255);
  83. $this->code = "";
  84. $this->inputCode = $_POST['captcha'];
  85. }
  86.  
  87. function createCaptcha() {
  88. for ($i = 0;
  89. $i < $this-captcha_length;
  90. $i ++)
  91. {
  92.  
  93. $x_axis = 20 + ($i * 20);
  94. $y_axis = 50 + rand (0, 7);
  95.  
  96. $color1 = rand (001, 150);
  97. $color2 = rand (001, 150);
  98. $color3 = rand (001, 150);
  99. $txt_color [$i] = ImageColorAllocate ($this->image, $color1, $color2, $color3);
  100.  
  101. $size = rand (20, 30);
  102.  
  103. $angle = rand (-15, 15);
  104.  
  105. $number = function ($len = 1)
  106. {
  107. $s = "";
  108. $b = "QWERTYUPASDFGHJKLZXCVBNMqwertyuopasdfghjkzxcvbnm123456789";
  109. while ($len-- > 0) {
  110. $s .= $b[mt_rand(0, strlen($b))];
  111. }
  112. return "$s";
  113. };
  114. $t = $number();
  115. $this->code .= "$t";
  116.  
  117. imagettftext ($this->image, $size, $angle, $x_axis, $y_axis, $txt_color[$i], "C:OSPaneldomainskultprosvetarial.ttf", $t);
  118. }
  119.  
  120. session_start();
  121.  
  122. $_SESSION ['captcha'] = $this->code;
  123.  
  124. header("Cache-Control: no-cache");
  125.  
  126. header("Content-type: image/jpg");
  127.  
  128. imagejpeg($this->image);
  129.  
  130. exit ();
  131. }
  132. }
  133.  
  134. <?php
  135. $captcha = new Captcha();
  136. $captcha->createCaptcha();
Add Comment
Please, Sign In to add comment