Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <html lang="pl">
  2. <head>
  3. <meta charset="utf8" />
  4. <title>Rysujemy captchę</title>
  5. <style>
  6.     #can {
  7.         border-style: solid;
  8.         border-width: 2px;
  9.         border-color: #404040;
  10.     }
  11. </style>
  12. </head>
  13. <body>
  14.     <canvas id="can" width="450" height="150"></canvas>
  15.     <?php
  16.         $captcha = '';
  17.         echo '<script>';
  18.         echo 'var can = document.getElementById("can");';
  19.         echo 'var c = can.getContext("2d");';
  20.         $alph = array_merge(range('a', 'z'), range('A', 'Z'), range('1', '9'));
  21.         $colors = array_merge(range('a', 'f'), range('0', '9'));
  22.         $fonts = array('Arial', 'Tahoma', 'Georgia', 'Verdana', 'Impact');
  23.         for($i = 1; $i < 9; $i++) {
  24.             $n = array_rand($alph);
  25.             $nc = array_rand($colors);
  26.             $nf = array_rand($fonts);
  27.             $letter = $alph[$n];
  28.             $font = $fonts[$nf];
  29.             $color = '#'.$colors[rand(0, 15)].$colors[rand(0, 15)].$colors[rand(0, 15)].$colors[rand(0, 15)].$colors[rand(0, 15)].$colors[rand(0, 15)];
  30.             echo 'c.font = "Bold 30px '.$font.'";';
  31.             echo 'c.fillStyle = "'.$color.'";';
  32.             echo 'c.fillText("'.$letter.'", 45*'.$i.', '.rand(20, 140).');';
  33.             $captcha .= $letter;
  34.         }
  35.         echo '</script><br />';
  36.         echo $captcha;
  37.     ?>
  38. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement