-
09-06
-
12-27
-
12-31
-
01-08
-
12-31
PHP创建验证
发布时间:2021-01-08 11:57:36
文章来源:原创
访问次数:36
<?php
ini_set('session.cookie_httponly', 1);
session_start();
/*设置输出格式*/
header('content-type:image/png');
/*设置宽高*/
$width = 70;
$height = 33;
/*绘制画布*/
$image = imagecreate($width, $height);
/*设置颜色*/
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
/*生成随机字符*/
$rand_str = '';
for ($i = 0; $i < 4; $i++){
$rand_str .= dechex(mt_rand(0,15));
}
/*设置状态*/
$_SESSION['code'] = $rand_str;
/*显示内容*/
imagefill($image, 0, 0, $white);
/*生成随机线条*/
for ($i=0; $i <mt_rand(1,5) ; $i++) {
$sjys = imagecolorallocate($image, mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
imageline($image, mt_rand(1,$width), mt_rand(1,$height), mt_rand(1,$width), mt_rand(1,$height), $sjys);
}
/*常规验证码
imagestring($image, 7, 7, 5, $rand_str, $white);//字体大小、宽度、高度常规
*/
/*复杂化验证码*/
for ($i=0; $i <strlen($_SESSION['code']) ; $i++) {
$sjys = imagecolorallocate($image, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
imagestring($image, mt_rand(3,8),$i * $width/4 + mt_rand(0,10) , mt_rand(5,10), $_SESSION['code'][$i], $sjys);/*字体大小、宽度、高度*/
}
/*绘制边框线*/
imagerectangle($image, 0, 0, $width-1, $height-1, $black);
/*输出图像*/
imagepng($image);
/*清除上方占用资源*/
imagedestroy($image);
?>本文链接:http://35.aizhanju.cnhttp://35.aizhanju.cn/php/62.html
文章评论
共 0 条评论,查看全部
- 这篇文章还没有收到评论,赶紧来抢沙发吧~
最新资讯


粤公网安备 34018102340473号
中国互联网举报中心