PHP我验证码的问题,有画布显示没有验证码提示,代码如下
发布网友
发布时间:2023-04-23 12:56
我来回答
共1个回答
热心网友
时间:2023-10-09 14:25
<?php
session_start();
ini_set('display_error', 'on');
error_reporting(E_ALL ^ E_NOTICE);
$Im = imagecreate(600, 250);
$BgColor = imagecolorallocate( $Im, 255, 255, 255 );
imagerectangle( $Im, 0, 0, 599, 249, imagecolorallocate( $Im, 0, 0, 0 ) );
$String = md5( rand() );
$Sess = '';
for ( $i = 0; $i < 5; $i++ ) {
$Code = $String{rand(0, strlen( $String ))};
$Sess .= $Code;
$str_x = floor( ( 600 / 5 ) * $i )+rand( 5, 10 );
$str_y = rand( 2, 250 - 15 );
$SColo = imagecolorallocate( $Im, rand( 0, 220 ),rand( 0, 220 ), rand( 0, 220 ) );
imagestring( $Im, 10, $str_x, $str_y, $Code, $SColo );
}
$_SESSION['code'] = $Sess;
header('content-type:image/*');
imagepng( $Im );
imagedestroy( $Im );
unset ( $BgColor, $Code, $i, $Im, $SColo, $Sess, $str_x, $str_y, $String );
效果: