PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ext_scripts/captcha.php

http://lansuite.googlecode.com/
PHP | 43 lines | 41 code | 2 blank | 0 comment | 0 complexity | 90504e7212368349404bb7ec3e985df6 MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. session_start();
  3. imageAuthCode(100, 20);
  4. function imageAuthCode($width, $height) {
  5. mt_srand((double)microtime()*1000000);
  6. $auth_code = mt_rand(1000, 99999);
  7. $auth_code = md5($auth_code);
  8. $auth_code = substr($auth_code, 0, 5);
  9. $auth_code = strtoupper($auth_code);
  10. setcookie('image_auth_code', md5($auth_code), time()+60*60 , '/');
  11. $image = imagecreate($width,$height) or die("Can't initialize GD image stream");
  12. $bg_color = imagecolorallocate($image, 240, 248, 255);
  13. $line_color = imagecolorallocate($image, 150, 150, 150);
  14. $elpise_color = imagecolorallocate($image, 200, 200, 200);
  15. $text_color = imagecolorallocate($image, 0, 0, 0);
  16. $rand1_h = mt_rand(1, $height);
  17. $rand2_h = mt_rand(1, $height);
  18. $rand3_h = mt_rand(1, $height);
  19. $rand4_h = mt_rand(1, $height);
  20. $rand1_v = mt_rand(1, $width);
  21. $rand2_v = mt_rand(1, $width);
  22. $rand3_v = mt_rand(1, $width);
  23. $rand4_v = mt_rand(1, $width);
  24. imageline($image, 0, $rand1_h, 100, $rand1_h, $line_color);
  25. imageline($image, 0, $rand2_h, 100, $rand2_h, $line_color);
  26. imageline($image, 0, $rand3_h, 100, $rand3_h, $line_color);
  27. imageline($image, 0, $rand4_h, 100, $rand4_h, $line_color);
  28. imageline($image, $rand1_v, 0, $rand1_v, 50, $line_color);
  29. imageline($image, $rand2_v, 0, $rand2_v, 50, $line_color);
  30. imageline($image, $rand3_v, 0, $rand3_v, 50, $line_color);
  31. imageline($image, $rand4_v, 0, $rand4_v, 50, $line_color);
  32. imagefilledellipse($image, mt_rand(0, 100), mt_rand(0, 40), mt_rand(10, 40), mt_rand(10, 25), $elpise_color);
  33. imagefilledellipse($image, mt_rand(0, 100), mt_rand(0, 40), mt_rand(20, 40), mt_rand(10, 25), $elpise_color);
  34. ImageTTFText ($image, 22, 0, 10, 20, $text_color, realpath('../ext_inc/fonts/captcha.ttf'), $auth_code);
  35. header("Content-type: image/png");
  36. imagepng($image);
  37. imagedestroy($image);
  38. }
  39. ?>