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

/core/captcha.php

http://rqcms.googlecode.com/
PHP | 41 lines | 28 code | 7 blank | 6 comment | 6 complexity | dec58a56c8aeb8e358a2b8cb070b96f6 MD5 | raw file
  1. <?php
  2. /**
  3. * ???????
  4. * @copyright (c) Emlog All Rights Reserved
  5. * @version emlog-3.5.0
  6. * $Id: checkcode.php 1698 2010-05-03 03:57:40Z emloog@gmail.com $
  7. */
  8. if(!defined('RQ_ROOT')) exit('Access Denied');
  9. doAction('captcha_create_myself');
  10. session_start();
  11. $randCode = '';
  12. $chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPRSTUVWXYZ23456789';
  13. for ( $i = 0; $i < 4; $i++ ){
  14. $randCode .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  15. }
  16. $_SESSION['code'] = strtoupper($randCode);
  17. $img = imagecreate(55,22);
  18. $bgColor = isset($_GET['mode']) && $_GET['mode'] == 't' ? imagecolorallocate($img,245,245,245) : imagecolorallocate($img,255,255,255);
  19. $pixColor = imagecolorallocate($img,mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
  20. for($i = 0; $i < 4; $i++){
  21. $x = $i * 13 + mt_rand(0, 4) - 2;
  22. $y = mt_rand(0, 3);
  23. $text_color = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
  24. imagechar($img, 5, $x + 5, $y + 3, $randCode[$i], $text_color);
  25. }
  26. for($j = 0; $j < 50; $j++){
  27. $x = mt_rand(0,55);
  28. $y = mt_rand(0,22);
  29. imagesetpixel($img,$x,$y,$pixColor);
  30. }
  31. header('Content-Type: image/png');
  32. imagepng($img);
  33. imagedestroy($img);
  34. exit();