<?php
Session_Start ();
function Random ($len) {
$srcstr = ' 0123456789asdfghjklzxcvbnmqwertyuiop ';
Mt_srand ();
$strs = "";
for ($i =0; $i < $len; $i + +) {
$strs. = $srcstr [Mt_rand (0,30)];
}
return $strs;
}
Randomly generated string
$str =random (4);
Verify the width of the code picture
$width = 80;
Verify the height of the code picture
$height = 40;
Declare the picture format of the layer you want to create
@header ("Content-type:image/png");
Create a layer
$im =imagecreate ($width, $height);
Background color
$back =imagecolorallocate ($im, 255,255,255);
Blur Point Color
$pix =imagecolorallocate ($im, 187,230,247);
Font Color
$font =imagecolorallocate ($im, 41,163,238);
Plot Blur points
Mt_srand ();
for ($i =0; $i <1000; $i + +)
{
Imagesetpixel ($im, Mt_rand (0, $width), Mt_rand (0, $height), $pix);
}
Output character
Imagestring ($im, 5,25,10, $str, $font);
Output layer
Imagepng ($im);
?>
Reference article: http://www.jb51.net/article/51506.htm
PHP Verification Code Function module