SidXSpam-image.php代码详解

 image.php主要是生成一个图片文件

  1. <?
  2.  
  3. $sxscode = '';//初始化
  4. $sxscode_len = 4;//验证码长度
  5.  
  6. //-----------
  7. //验证码范围,如果包含字母+数字组合则保留前一句,只需要数字则保留后一句
  8. $sxsarray = array('a','b','c','d','e','f','g','h','i','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0');
  9. //$sxsarray = array('1','2','3','4','5','6','7','8','9','0');
  10. //-----------
  11.  
  12. //随机排序数列
  13. shuffle($sxsarray);
  14.  
  15. //随机数种子,PHP版本>4.2 可去除
  16. function make_seed() {
  17. list($usec, $sec) = explode(' ', microtime());
  18. return (float)$sec + ((float)$usec * 100000);
  19. }
  20. mt_srand(make_seed());
  21. //------------------------------
  22.  
  23.  
  24. //获取随机数
  25. for( ;strlen($sxscode)<=$sxscode_len-1; ){
  26. $sxscode .= $sxsarray[mt_rand(0, count($sxsarray))];
  27. }
  28.  
  29.  
  30. //写入服务器session,需要服务器session支持
  31. @session_start();
  32. $_SESSION['sxscode'] = $sxscode;
  33. $_SESSION['sxscode_offtime'] = time() + 15 * 60;
  34.  
  35. //绘图,输出
  36. $im = imagecreate(50,20);
  37. $white = ImageColorAllocate($im, 255,255,255);
  38. $black = ImageColorAllocate($im, 0,0,0);
  39. imagestring($im, 5, 6, 3, $sxscode, $black);
  40. header("Content-type: image/PNG");
  41. ImagePNG($im);
  42. ImageDestroy($im);
  43. ?>
该文章发布在 PHP, wordpress。收藏该永久链接

评论功能被关闭。