PHP development...LOGIN

PHP development verification code tutorial to implement digital verification code

Implementing digital verification code

<?php
$image = imagecreatetruecolor(100,30);
$bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF
imagefill($image,0,0,$bgcolor);
for ($i=0;$i<4;$i++){
    $fontsize = 6;
    $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
    $fontcontent = rand(0,9);
    $x = ($i * 100/4)+rand(5,10);
    $y = rand(5,10);
    imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
header('content-type: image/png');
imagepng($image);
//销毁
imagedestroy($image);
?>

for ($i=0;$i<4;$i++){
//循环出四个数字
    $fontsize = 6;//字体的大小为6
    $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120)); 
//定义字体的颜色
    $fontcontent = rand(0,9);//定义字体的取值范围
}$x = ($i * 100/4)+rand(5,10);
$y = rand(5,10); 
在范围内随机定义坐标
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}

imagestring() uses col color to draw the string s to x of the image represented by image, y coordinate (this is the coordinate of the upper left corner of the string, the upper left corner of the entire image is 0, 0). If font is 1, 2, 3, 4 or 5, the built-in font is used.

Note: Control the size and distribution of fonts to avoid overlapping and incomplete display of fonts

Next Section
<?php $image = imagecreatetruecolor(100,30); $bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF imagefill($image,0,0,$bgcolor); for ($i=0;$i<4;$i++){ $fontsize = 6; $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120)); $fontcontent = rand(0,9); $x = ($i * 100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } header('content-type: image/png'); imagepng($image); //销毁 imagedestroy($image); ?>
submitReset Code
ChapterCourseware