PHP全栈学习笔记26

版权声明:本文为博主原创文章,未经博主允许不得转载,达叔小生:往后余生,唯独有你 https://blog.csdn.net/qq_36232611/article/details/89814881

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);
?>

猜你喜欢

转载自blog.csdn.net/qq_36232611/article/details/89814881