Advertisement
tvilling53

captcha

Jul 12th, 2017
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2. session_start();//projekt 2
  3. header("Content-type: image/jpeg");
  4. header("Cache-Control: no-cache, must-revalidate");
  5. header("Pragma: no-cache");
  6.  
  7.  
  8. $skrifttyper[] = 'OpenSans-Regular.ttf';//"Arial.ttf";
  9. $skrifttyper[] = 'Oswald-Regular.ttf';//"Tahoma.ttf";
  10. $skrifttyper[] = 'Raleway-Regular.ttf';//"Impact.ttf";
  11. $skrifttyper[] = 'Ubuntu-Medium.ttf';//"Verdana.ttf";
  12. $skrifttyper[] = 'Dosis-Medium.ttf';//"Georgia.ttf";
  13.  
  14.  
  15. $width=250;
  16. $height=60;
  17.  
  18. $image = imagecreatetruecolor($width,$height);//Danner billedet
  19.  
  20. $y=0;$x=0;
  21. for($i=0;$i<($width*$height);$i++)
  22. { $color = imagecolorallocate($image, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));
  23. imagesetpixel($image, ($x - 1), $y, $color);
  24. $x += 1;
  25. if($x >= $width)
  26. { $y += 1;
  27. $x = 1;
  28. }
  29. }
  30. //----------------laver security-kode til brug i ny-bruger.php---------------
  31. $input='';
  32. $tegn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz";
  33. for($i=0;$i<6;$i++)
  34. { $input.=substr($tegn, mt_rand(0, (strlen($tegn) - 1)), 1);
  35. }
  36. //-----------------indsætter security-kode i SESSION som bruges i opret-bruger.php-----------------
  37. $_SESSION['security_code'] = $input;
  38. $x = mt_rand(5, 35);//Startpunkt 10,$height
  39. $y = mt_rand(35, 50);//Startpunkt 35,50
  40.  
  41. for($i=0;$i<strlen($input);$i++)
  42. { $color = imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155));
  43. $font = "font/".$skrifttyper[mt_rand(0, (count($skrifttyper) - 1))];
  44. //$font = "C:/Windows/Fonts/".$skrifttyper[mt_rand(0, (count($skrifttyper) - 1))];
  45. imagettftext($image, mt_rand(25, 30), mt_rand(-10, 10), $x, $y, $color, $font, substr($input, $i, 1));
  46. $x += mt_rand(25, 40);
  47. $y += mt_rand(-5, 5);
  48. }
  49.  
  50. for($i=0;$i<mt_rand(4, 6);$i++)
  51. { $color = imagecolorallocate($image, mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $width));
  52. if(mt_rand(0, 2) == 1)
  53. { imageellipse($image, mt_rand(50,150), mt_rand(10, 50), mt_rand(10, $height), mt_rand(10, $height),$color);
  54. }
  55. else
  56. { imageline($image, mt_rand(0, 50), mt_rand(0, $height), mt_rand(100, $width), mt_rand(0, $height), $color);
  57. }
  58. }
  59. for($i=0;$i<mt_rand(250, 500);$i++)
  60. { $color = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  61. imagesetpixel($image, mt_rand(0, $width), mt_rand(0, $height), $color);
  62. }
  63.  
  64. imagejpeg($image);
  65. ImageDestroy($image);
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement