[PHP] php生成验证码 支持中文 字母 数字混合 →→→→→进入此内容的聊天室

来自 , 2019-08-05, 写在 PHP, 查看 111 次.
URL http://www.code666.cn/view/a3788c8c
  1. <?php
  2.  //验证码的制作
  3.  //1.生成4位的随机数
  4.  for($i=0;$i<4;$i++){
  5.      $rand.=dechex(rand(1, 15));
  6.  }
  7.  
  8.  //2.创建图片
  9.  //创建一张图片
  10.  $image=imagecreatetruecolor(100, 30);
  11.  //背景颜色
  12.  $bg=imagecolorallocate($image, 0, 0, 0);
  13.  $te=imagecolorallocate($image, 255,255,255);
  14.  
  15.  
  16.  //划线
  17.  for($i=0;$i<4;$i++){
  18.      $lineColor=imagecolorallocate($image, rand(20, 225), rand(20, 225), rand(20, 225));
  19.      imageline($image, rand(0, 100), 0, 100,30, $lineColor);
  20.  }
  21.  //划点
  22.  for($i=0;$i<200;$i++){
  23.      imagesetpixel($image, rand()%100, rand()%100, $lineColor);
  24.  }
  25.  //添加文字
  26.  //编码转换
  27.  $str=iconv("GBK", "UTF-8", "广州GZ");
  28.  imagettftext($image, 12,11, 20, 20, $lineColor, 'simhei.ttf', $str);
  29.  
  30.  //3.随机数写入图片$font=(1~6)
  31.  imagestring($image, rand(3, 6), rand(3, 70), rand(0, 16), $rand, $te);
  32.  
  33.  //4.随机数保存在session中
  34.  //启动session
  35.  //把验证码放入session
  36.  $_SESSION[vilidationCode]=$rand;
  37.  
  38.  
  39.  header("Content-type: image/jpeg");
  40.  imagejpeg($image);
  41.  ?>

回复 "php生成验证码 支持中文 字母 数字混合"

这儿你可以回复上面这条便签

captcha