• <tfoot id='ZBRYi'></tfoot>
    <i id='ZBRYi'><tr id='ZBRYi'><dt id='ZBRYi'><q id='ZBRYi'><span id='ZBRYi'><b id='ZBRYi'><form id='ZBRYi'><ins id='ZBRYi'></ins><ul id='ZBRYi'></ul><sub id='ZBRYi'></sub></form><legend id='ZBRYi'></legend><bdo id='ZBRYi'><pre id='ZBRYi'><center id='ZBRYi'></center></pre></bdo></b><th id='ZBRYi'></th></span></q></dt></tr></i><div id='ZBRYi'><tfoot id='ZBRYi'></tfoot><dl id='ZBRYi'><fieldset id='ZBRYi'></fieldset></dl></div>

        <bdo id='ZBRYi'></bdo><ul id='ZBRYi'></ul>
    1. <small id='ZBRYi'></small><noframes id='ZBRYi'>

      <legend id='ZBRYi'><style id='ZBRYi'><dir id='ZBRYi'><q id='ZBRYi'></q></dir></style></legend>

        PHP图形验证码实例代码

        时间:2024-10-29

      1. <small id='YvLrE'></small><noframes id='YvLrE'>

            <i id='YvLrE'><tr id='YvLrE'><dt id='YvLrE'><q id='YvLrE'><span id='YvLrE'><b id='YvLrE'><form id='YvLrE'><ins id='YvLrE'></ins><ul id='YvLrE'></ul><sub id='YvLrE'></sub></form><legend id='YvLrE'></legend><bdo id='YvLrE'><pre id='YvLrE'><center id='YvLrE'></center></pre></bdo></b><th id='YvLrE'></th></span></q></dt></tr></i><div id='YvLrE'><tfoot id='YvLrE'></tfoot><dl id='YvLrE'><fieldset id='YvLrE'></fieldset></dl></div>
          • <tfoot id='YvLrE'></tfoot>

              <legend id='YvLrE'><style id='YvLrE'><dir id='YvLrE'><q id='YvLrE'></q></dir></style></legend>
                <tbody id='YvLrE'></tbody>

                • <bdo id='YvLrE'></bdo><ul id='YvLrE'></ul>
                • PHP支持许多的函数,其中一些函数完全可以将字符串,制作为图片,将画布背景放上一些乱码,再挑选四个数字(你也可以添加字母,但是那样会比较花)。按照不同的角度放在画布上。具体代码如下:
                  <?php
                  //设置字符集
                  header("Content-Type:text/html;charset=utf-8");
                  
                  //图宽
                  $width = 150;
                  //图高
                  $height = 40;
                  //验证码的长度
                  $length = 4;
                  //字体样式
                  $fontstyle = './font/MSYHBD.TTF';
                  //字体大小
                  $fontsize = 20;
                  
                  //1.创建画布
                  $img = imagecreatetruecolor($width, $height);
                  
                  //2.分配颜色
                  $bgcolor = imagecolorallocate($img, mt_rand(180, 240), mt_rand(180, 240), mt_rand(180, 240));
                  
                  //3.填充
                  imagefill($img, 0, 0, $bgcolor);
                  
                  
                  //4.画干扰
                  $str = '~~~~~~~~~~~~~~~~~~~~!@#$%%^^&*()_+.,[]:<>';  
                  $str_len = strlen($str);
                  for ($i = 0; $i < $str_len; $i++) {
                      //分配字体颜色
                      $fontcolor = imagecolorallocate($img, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
                      imagettftext($img, 8, mt_rand(0, 360), mt_rand(0, $width), mt_rand(0, $height), $fontcolor, $fontstyle, $str[$i]);
                  }
                  
                  
                  //5.生成随机验证码
                  $code_small = range('a', 'z');
                  $code_big = range('A', 'Z');
                  $code_num = range('0', '9');
                  
                  //6.合并成一个数组
                  $list = array_merge($code_small, $code_big, $code_num);
                  //7.随机打乱顺序
                  shuffle($list);
                  
                  //8.用于储存验证码
                  $code = '';
                  for ($i = 0; $i < $length; $i++) {
                      //分配字体颜色
                      //分配字体颜色
                      $fontcolor = imagecolorallocate($img, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
                      imagettftext(
                          $img,   //操作目标
                          $fontsize,  //字体大小
                          mt_rand(-40, 40), //角度
                          (($i * $fontsize) + ($width - ($length + $fontsize) >> 1)),   //字体横坐标X
                          (($height - $fontsize >> 1) + $fontsize), //字体纵坐标Y
                          $fontcolor, //字体颜色
                          $fontstyle, //字体样式
                          $list[$i]   //字体内容
                      );
                      $code .= $list[$i];
                  }
                  
                  //9.开启会话
                  session_start();
                  //10.将正确验证码放入session
                  $_SESSION['code'] = $code;
                  
                  header('Content-Type:image/png');
                  imagepng($img);
                  imagedestroy($img);
                  ?>
                   
                  上一篇:php获取数组中某一个元素的值,并用逗号分隔 下一篇:没有了

                  相关文章

                  <legend id='DSFK5'><style id='DSFK5'><dir id='DSFK5'><q id='DSFK5'></q></dir></style></legend>
                    <i id='DSFK5'><tr id='DSFK5'><dt id='DSFK5'><q id='DSFK5'><span id='DSFK5'><b id='DSFK5'><form id='DSFK5'><ins id='DSFK5'></ins><ul id='DSFK5'></ul><sub id='DSFK5'></sub></form><legend id='DSFK5'></legend><bdo id='DSFK5'><pre id='DSFK5'><center id='DSFK5'></center></pre></bdo></b><th id='DSFK5'></th></span></q></dt></tr></i><div id='DSFK5'><tfoot id='DSFK5'></tfoot><dl id='DSFK5'><fieldset id='DSFK5'></fieldset></dl></div>
                    <tfoot id='DSFK5'></tfoot>

                    <small id='DSFK5'></small><noframes id='DSFK5'>

                      • <bdo id='DSFK5'></bdo><ul id='DSFK5'></ul>