Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $captcha_length = 6;
- $image = imagecreatetruecolor ( 200, 75 );
- $back_color = @ImageColorAllocate ( $image, 255, 255, 255 );
- $code = "";
- $inputCode = $_POST['captcha'];
- for($i = 0; $i < $captcha_length; $i ++) {
- $x_axis = 20 + ($i * 20);
- $y_axis = 50 + rand ( 0, 7 );
- $color1 = rand ( 001, 150 );
- $color2 = rand ( 001, 150 );
- $color3 = rand ( 001, 150 );
- $txt_color [$i] = ImageColorAllocate ( $image, $color1, $color2, $color3 );
- $size = rand ( 20, 30 );
- $angle = rand ( -15, 15 );
- $number = function ($len=1) {
- $s = "";
- $b="QWERTYUPASDFGHJKLZXCVBNMqwertyuopasdfghjkzxcvbnm123456789";
- while($len-->0) {
- $s.=$b[mt_rand(0,strlen($b))];
- }
- return "$s";
- };
- $t = $number();
- $code .= "$t";
- imagettftext ( $image, $size, $angle, $x_axis, $y_axis, $txt_color[$i], "C:OSPaneldomainskultprosvetarial.ttf", $t);
- }
- session_start();
- $_SESSION ['captcha'] = $code;
- header ( "Cache-Control: no-cache" );
- header ( "Content-type: image/jpg" );
- imagejpeg ( $image);
- exit ();
- <form id = "form">
- <input id = "name" type = "text" minlength="2" placeholder="Ваше имя" name = "name" required>
- <input id = "s_name" type = "text" placeholder="Ваша фамилия" name = "s_name" required>
- <input id = "email" type = "text" placeholder="email" name = "email" required>
- <select id = "ticket" required name = "ticket">
- <option>free</option>
- <option>standart</option>
- <option>premium</option>
- </select>
- <img alt="" id="captcha" src="captcha.php" />
- <span onclick="document.getElementById('captcha').src=document.getElementById( 'captcha').src + '?' + Math.random();">обновить код</span>
- <input type="text" maxlength="<?=$captcha_length;?>" style="text-align: center;" autocomplete="off" name="captcha" value=""/>
- <input id = "submit" type = "submit">
- </form>
- <?php
- class Captcha
- {
- public $captcha_length;
- public $image;
- public $back_color;
- public $code;
- public $inputCode;
- function __construct(){
- parent::__construct();
- $this->captcha_length = 6;
- $this->image = imagecreatetruecolor (200, 75);
- $this->back_color = @ImageColorAllocate ($this->image, 255, 255, 255);
- $this->code = "";
- $this->inputCode = $_POST['captcha'];
- }
- function createCaptcha() {
- for ($i = 0;
- $i < $this-captcha_length;
- $i ++)
- {
- $x_axis = 20 + ($i * 20);
- $y_axis = 50 + rand (0, 7);
- $color1 = rand (001, 150);
- $color2 = rand (001, 150);
- $color3 = rand (001, 150);
- $txt_color [$i] = ImageColorAllocate ($this->image, $color1, $color2, $color3);
- $size = rand (20, 30);
- $angle = rand (-15, 15);
- $number = function ($len = 1)
- {
- $s = "";
- $b = "QWERTYUPASDFGHJKLZXCVBNMqwertyuopasdfghjkzxcvbnm123456789";
- while ($len-- > 0) {
- $s .= $b[mt_rand(0, strlen($b))];
- }
- return "$s";
- };
- $t = $number();
- $this->code .= "$t";
- imagettftext ($this->image, $size, $angle, $x_axis, $y_axis, $txt_color[$i], "C:OSPaneldomainskultprosvetarial.ttf", $t);
- }
- session_start();
- $_SESSION ['captcha'] = $this->code;
- header("Cache-Control: no-cache");
- header("Content-type: image/jpg");
- imagejpeg($this->image);
- exit ();
- }
- }
- <?php
- $captcha = new Captcha();
- $captcha->createCaptcha();
Add Comment
Please, Sign In to add comment