PageRenderTime 89ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/captcha.php

https://github.com/buffala/Pizza
PHP | 39 lines | 28 code | 10 blank | 1 comment | 2 complexity | fe9a2d726b8541f7aa913bb2f3201d99 MD5 | raw file
  1. <?php
  2. session_start();
  3. $width = 120;
  4. $height = 40;
  5. $length = 5;
  6. $baseList = '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ';
  7. $code = "";
  8. $counter = 0;
  9. $image = @imagecreate($width, $height)
  10. or die('Cannot initialize captcha!');
  11. for ($i=0; $i<10; $i++){
  12. imageline($image,mt_rand(0,$width), mt_rand(0,$height),
  13. mt_rand(0,$width), mt_rand(0,$height),
  14. imagecolorallocate($image,mt_rand(150,255),
  15. mt_rand(150,255),
  16. mt_rand(150,255)));
  17. }
  18. for ($i=0,$x=0;$i<$length;$i++){
  19. $actChar = substr($baseList,rand(0,strlen($baseList)-1),1);
  20. $x += 10 + mt_rand(0,10);
  21. //imagechar($image,mt_rand(12,),$x,mt_rand(5,20), $actChar,imagecolorallocate($image,mt_rand(0,155), mt_rand(0,155), mt_rand(0,155)));
  22. imagettftext($image,mt_rand(12,16),0,$x,mt_rand(5,20),imagecolorallocate($image,mt_rand(0,155), mt_rand(0,155), mt_rand(0,155)), 'fonts/' . rand(1,4) . '.ttf',$actChar);
  23. $code .= strtolower($actChar);
  24. }
  25. header('Content-Type: Image/jpeg');
  26. imagejpeg($image);
  27. imagedestroy($image);
  28. $_SESSION['securityCode'] = $code;
  29. ?>