Discuz教程网

PHP生成验证码图片

[复制链接]
authicon 09927306 发表于 2011-1-6 12:32:47 | 显示全部楼层 |阅读模式
  1. <?
  2. //checkNum.php
  3. session_start();
  4. function random($len)
  5. {
  6. $srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  7. mt_srand();
  8. $strs="";
  9. for($i=0;$i<$len;$i++){
  10. $strs.=$srcstr[mt_rand(0,35)];
  11. }
  12. return strtoupper($strs);
  13. }
  14. $str=random(4); //随机生成的字符串
  15. $width = 50; //验证码图片的宽度
  16. $height = 25; //验证码图片的高度
  17. @header("Content-Type:image/png");
  18. $_SESSION["code"] = $str;
  19. //echo $str;
  20. $im=imagecreate($width,$height);
  21. //背景色
  22. $back=imagecolorallocate($im,0xFF,0xFF,0xFF);
  23. //模糊点颜色
  24. $pix=imagecolorallocate($im,187,230,247);
  25. //字体色
  26. $font=imagecolorallocate($im,41,163,238);
  27. //绘模糊作用的点
  28. mt_srand();
  29. for($i=0;$i<1000;$i++)
  30. {
  31. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
  32. }
  33. imagestring($im, 5, 7, 5,$str, $font);
  34. imagerectangle($im,0,0,$width-1,$height-1,$font);
  35. imagepng($im);
  36. imagedestroy($im);
  37. $_SESSION["code"] = $str;
  38. ?>
复制代码







上一篇:php显示目录下所有文件
下一篇:PHP汉字验证码的实现
authicon haidideyu 发表于 2011-6-17 07:01:37 | 显示全部楼层
哈哈,支持了
authicon Pianissimo 发表于 2011-6-18 09:59:54 | 显示全部楼层
顶啦,不错吧
authicon kurt226 发表于 2011-6-25 16:59:45 | 显示全部楼层
看一下啊,嘻嘻
authicon shakesxia 发表于 2011-6-25 18:00:12 | 显示全部楼层
真的有意思!
authicon kurt226 发表于 2011-6-25 21:59:56 | 显示全部楼层
我回不回呢 考虑再三 还是不回了吧 ^_^
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-6 05:47

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表