PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_chronocontact/chrono_verification.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 83 lines | 79 code | 0 blank | 4 comment | 0 complexity | 755aefe81e9111c922cb65270980ad85 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. //Chrono CAPTCHA V 1.0
  3. //You are not allowed to use this piece of code without the ChronoForms package, or without a license for it
  4. //In order to use this piece of code at your own application you must have a license for it alone (ChronoCAPTCHA) OR have ChronoForms license, otherwise it only helps the function of ChronoForms ONLY
  5. //you are not allowed to edit,copy or reditribute this piece of code under your own name/brand
  6. session_start();
  7. $alphanum = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghijkmnpqrstuvwxyz";
  8. $rand = substr(str_shuffle($alphanum), 0, 5);
  9. $alphanum2 = "ABCDEFGHIJKLMNPQRSTUVWXYZ23456789abcdefghijkmnpqrstuvwxyz?><,.|\"'[{]}_=+*&^%$#@!~";
  10. $rand2 = substr(str_shuffle($alphanum), 0, 7);
  11. $_SESSION['chrono_verification'] = md5(strtolower($rand));
  12. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  13. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  14. header("Cache-Control: no-store, no-cache, must-revalidate");
  15. header("Cache-Control: post-check=0, pre-check=0", false);
  16. header("Pragma: no-cache");
  17. //header("Content-type: image/png");
  18. $font = dirname(__FILE__).'/default.ttf';
  19. $image_size = imagettfbbox(20, 0, $font, 'X');
  20. $image_size = 5*(abs($image_size[2] - $image_size[0])+7);
  21. $im = imagecreatetruecolor($image_size, 40);
  22. // Create some colors
  23. $white = imagecolorallocate($im, 255, 255, 255);
  24. $grey = imagecolorallocate($im, 128, 128, 128);
  25. $greylight = imagecolorallocate($im, 199, 199, 199);
  26. $black = imagecolorallocate($im, 0, 0, 0);
  27. imagefilledrectangle($im, 0, 0, $image_size -1, 39, $white);
  28. // The text to draw
  29. $text = $rand;
  30. // Replace path by your own font path
  31. $font = dirname(__FILE__).'/default.ttf';
  32. $chars = array();
  33. $chars2 = array();
  34. for ($i = 0; $i < strlen($text); $i++) { $chars[] = $text[$i]; }
  35. for ($i = 0; $i < strlen($rand2); $i++) { $chars2[] = $rand2[$i]; }
  36. //$chars = str_split($text);
  37. //$chars2 = str_split($rand2);
  38. // Add some shadow to the text
  39. //imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
  40. $size2 = 20;
  41. $angle2 = 0;
  42. $x2 = 10;
  43. $y2 = 25;
  44. $bbox2 = array();
  45. $bbox2[0] = 0;
  46. $bbox2[2] = 0;
  47. foreach($chars2 as $char2){
  48. $angle2 = rand(-20, 20);
  49. $size2 = rand(15, 20);
  50. $y2 = rand(0, 40);
  51. imagettftext($im, $size2, $angle2, $x2, $y2, $greylight, $font, $char2);
  52. $bbox2 = imagettfbbox($size2, $angle2, $font, $char2);
  53. $x2 = $x2 + abs($bbox2[2] - $bbox2[0]) + 3;
  54. }
  55. $size = 20;
  56. $angle = 0;
  57. $x = 10;
  58. $y = 25;
  59. $bbox = array();
  60. $bbox[0] = 0;
  61. $bbox[2] = 0;
  62. // Add the text
  63. foreach($chars as $char){
  64. $angle = rand(-20, 20);
  65. //$size = rand(15, 20);
  66. imagettftext($im, $size, $angle, $x, $y, $black, $font, $char);
  67. $bbox = imagettfbbox($size, $angle, $font, $char);
  68. $x = $x + abs($bbox[2] - $bbox[0]) + 3;
  69. }
  70. // Using imagepng() results in clearer text compared with imagejpeg()
  71. imagepng($im);
  72. imagedestroy($im);
  73. ?>