日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php随机产生4位的验证码

發布時間:2024/4/17 php 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php随机产生4位的验证码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<?php
  function getVerify($width=80,$height=30,$type=3,$length=4,$pixel=50,$line=5){
  //創建畫布
  $image = imagecreatetruecolor($width,$height);
  //創建畫筆白色,用于填充
  $white = imagecolorallocate($image,255,255,255);
  //產生隨機色
  function getRandColor($image){
    return imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  }
  //創建填充矩形
  imagefilledrectangle($image,0,0,$width,$height,$white);

  switch($type){
    case 1:
      $str = join('',array_rand(range(0,9),$length));
    break;
    case 2:
      $str = join('',array_rand(array_flip(array_merge(range('a','z'),range('A','Z'))),$length));
    break;
    case 3:
      $str = join('',array_rand(array_flip(array_merge(range(0,9),range('a','z'),range('A','Z'))),$length));
    break;
    default:
      exit('非法參數!!');
    break;
    }

    for($i=0;$i<$length;$i++){
      $size = mt_rand(20,24);
      $angle = mt_rand(-15,15);
      $x = imagefontwidth(20) + 20*$i;
      $y = 25;
      $font = 'fonts/simkai.ttf';
      $text = substr($str,$i,1);
      imagettftext($image,$size,$angle,$x,$y,getRandColor($image),$font,$text);
    }

    //添加干擾元素

    if($pixel){
      for($i=0;$i<$pixel;$i++){
        imagesetpixel($image,mt_rand(0,$width),mt_rand(0,$height),getRandColor($image));
      }
    }

    //添加干擾線段
    if($line){
      for($m=0;$m<$line;$m++){
        imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),getRandColor($image));
      }
    }

  header('content-type:image/png');
  imagepng($image);
  imagedestroy($image);
  }
  getVerify();

轉載于:https://www.cnblogs.com/coolkaier/p/6698169.html

總結

以上是生活随笔為你收集整理的php随机产生4位的验证码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。