-
09-06
-
12-27
-
01-08
-
12-31
-
12-31
Warning: error_log(/home/wwwroot/zym.qw1688.net/cache/error_log.php): failed to open stream: Permission denied in /home/wwwroot/zym.qw1688.net/yzmphp/core/class/debug.class.php on line 63
发布时间:2021-01-08 11:57:36
文章来源:原创
访问次数:2
09-06
12-27
01-08
12-31
12-31
<?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://www.hzlm.net/php/62.html