PHP全栈学习笔记26

php 验证码
image.png

<?php
/*
*@Author: 达叔小生
**/
header("Content-type:image/png");	// 发送头部信息,生成png图片文件
$str = 'qwertyuiopasdfghjklzxcvbnm1234567890';
$l = strlen($str);//得到字符串的长度
$authnum = '';
for($i=1;$i<=4;$i++){
    $num = rand(0,$i-1);//每次随机抽取一位数字
    $authnum.=$str[$num];//将通过数字得来的字符串连起来
}
srand((double)microtime()*1000000);
$im = imagecreate(50,20);
$black = imagecolorallocate($im,0,0,0);
$white = imagecolorallocate($im,255,255,255);
$gray = imagecolorallocate($im,200,200,200);
imagefill($im,68,30,$black);
imagestring($im,5,8,2, $authnum, $white);
imagepng($im);
imagedestroy($im);
?>
posted @ 2019-05-04 16:30  达达前端  阅读(107)  评论(0编辑  收藏  举报