本篇文章介绍的内容是php生成随机验证码 ,现在分享给大家,有需要的朋友可以参考一下
<?php
/**
* 生成随机字符串
* @param int $num 生成的随机字符串的个数
* @return str 生成的随机字符串
*/
function randStr($num=6) {
$str = str_shuffle('abcedfghjkmnpqrstuvwxyzABCEDFGHJKMNPQRSTUVWXYZ23456789');
return substr($str, 0 , $num);
}
//1.创建画布
$pic = imagecreatetruecolor(80, 50);
//2.创建颜料(RGB)
$red = imagecolorallocate($pic, 255, 0, 0);
$blue = imagecolorallocate($pic, 127, 127, 127);
//3.背景填充
imagefill($pic, 0, 0, $red);
//4.写入文字
imagestring($pic, 5, 5, 5, randStr(4), $blue);
//5. 输出/保存图形
header('Content-type:image/png');
imagepng($pic);
//6. 销毁画布(关闭画板)
imagedestroy($pic);
?>相关推荐:
以上就是008-php生成随机验证码 的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号