PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/include/lib/checkcode.php

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