php生成数字字母的验证码图片

yipeiwu_com6年前PHP代码库

php生成数字字母的验证码图片

<?php

header ('Content-Type: image/png');
$image=imagecreatetruecolor(100, 30);
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 20, 20, $color);
//只含有数字
// for($i=0;$i<4;$i++){
  // $font=6;
  // $x=rand(5,10)+$i*100/4;
  // $y=rand(8, 15);
  // $string=rand(0, 9);
  // $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  // imagestring($image, $font, $x, $y, $string, $color);
// }

//含有数字和字母的
for($i=0;$i<4;$i++){
  $fontSize=6;
  $x=rand(5,10)+$i*100/4;
  $y=rand(5, 15);
  $data='abcdefghijklmnopqrstuvwxyz123456789';
  $string=substr($data,rand(0, strlen($data)),1);
  $color=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));
  imagestring($image, $fontSize, $x, $y, $string, $color);
}
//干扰点元素
for($i=0;$i<200;$i++){
  $pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
  imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
}
//干扰线元素
for($i=0;$i<2;$i++){
  $linePoint=imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
  imageline($image, rand(10, 50), rand(10, 20), rand(80,90), rand(15, 25), $linePoint);
}
imagepng($image);
imagedestroy($image);
?>

以上所述就是本文的全部内容了,希望大家能够喜欢。

相关文章

php注册登录系统简化版

php注册登录系统简化版

登录注册系统是日常上网最普通的操作,我设了一个分类一步步完善注册登录系统,若哪里有误,请见谅。 所用语言:php 数据库 :mysql 本次实现功能: 1.用户注册 2.用户登录 主要文...

Admin generator, filters and I18n

Three easy steps 1) configure function Add an input for each field you want to include in you...

php中分页及SqlHelper类用法实例

php中分页及SqlHelper类用法实例

本文实例讲述了php中分页及SqlHelper类用法。分享给大家供大家参考,具体如下: 文档目录结构如下: SqlHelper.php代码如下: <?php /**...

解决php-fpm.service not found问题的办法

前言 本文给大家详细介绍了解决php-fpm.service not found问题的相关内容,文中介绍的非常详细,下面来一起看看详细的介绍: 环境介绍 环境:ubuntu 16.04...

深入理解PHP原理之执行周期分析

本文讲述了PHP原理之执行周期。分享给大家供大家参考,具体如下: PHP的执行周期,从最初我们编写的PHP脚本->到最后脚本被执行->得到执行结果,这个过程,其实可以分为如下...