zoukankan      html  css  js  c++  java
  • php写的验证码实现方法

    <?php
      header("Content-type:image/png");
      //$num=$_GET['num'];  这里本来是想获取的,但是为了方便显示,用了下面一条语句直接得到了。
      $num="we5523";
      $imagewidth=80;
      $imageheight=18;
     
      $numimage= imagecreate($imagewidth, $imageheight);//按照上面的大小建立一张图片
      imagecolorallocate($numimage, 240, 240, 240);  //为该图片设背景色
      for($i=0;$i<strlen($num);$i++)//循环生成图片文字
      {
          $x = mt_rand(1, 8)+$imagewidth*$i/6; 
          $y = mt_rand(1,$imageheight/6);
          //为文字分配颜色、
          $color = imagecolorallocate($numimage,mt_rand(0,150), mt_rand(0, 150), mt_rand(0, 150));
          imagestring($numimage, 5, $x, $y, $num[$i], $color);  //写入文字
      }
     
     
      //生成干扰码
       for($i=0; $i<200;$i++)
      {
          $randcolor = imagecolorallocate($numimage, rand(200, 255), rand(200, 255), rand(200, 255));
          imagesetpixel($numimage, rand()%70, rand()%20, $randcolor);
      }
     
      $img=imagepng($numimage);  //输出图片
      echo "<img src='img.png'/>";
      imagedestroy($numimage);  //销毁图片

    ?>

     





    //直接拷贝放入php文件中,运行即可用。

  • 相关阅读:
    2013上半年中国CRM市场分析报告
    windows运行命令大全
    JVM探索(二)
    JVM探索(一)
    1.数据结构和算法的基础笔记
    java程序性能优化
    http状态码
    mongodb清洗数据
    List的数据结构
    Foundation Data Structure
  • 原文地址:https://www.cnblogs.com/wanlxz/p/2626919.html
Copyright © 2011-2022 走看看