Implementation code:
Save the Verification code to the session for global use
Session_Start ();
$nums = "";
for ($i =0; $i <4; $i + +) {
Generate random numbers and convert to hexadecimal
$nums. =dechex (Mt_rand (0,15));
}
Write verification code to session
$_session[' code ']= $nums;
Set the verification code length and width
$_width = 60;
$_height = 20;
Create a picture
$_img = Imagecreatetruecolor ($_width,$_height);
Create a White
$_white = Imagecolorallocate ($_img,220,250,250);
Fill background
Imagefill ($_img,0,0,$_white);
Randomly draw 6 lines
for ($i =0; $i <6; $i + +) {
$_rnd_color = Imagecolorallocate ($_img,mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255));
Imageline ($_img,mt_rand (0,$_width), Mt_rand (0,$_width), Mt_rand (0,$_width), Mt_rand (0,$_width), $_rnd_color);
}
To draw a snowflake randomly
for ($i =0; $i <60; $i + +) {
Imagestring ($_img,1,mt_rand (1,$_width), Mt_rand (1,$_height), "*", Imagecolorallocate ($_img,mt_rand (200,255), Mt_ Rand (200,255), Mt_rand (200,255));
}
Output Verification Code
for ($i =0; $i
Imagestring ($_img,mt_rand (6,10), $i *$_width/4+mt_rand (1,10), Mt_rand (1,$_ HEIGHT/2), $_session[' Code ' [$i],imagecolorallocate ($_img,mt_rand (0,100), Mt_rand (0,150), Mt_rand (0,200)));
}
//output and Destroy
Header ("Content-type:image/png");
Imagepng ($_IMG);
Imagedestroy ($_IMG);
?>
http://www.bkjia.com/phpjc/768133.html www.bkjia.com True http://www.bkjia.com/phpjc/768133.html techarticle implementation code:? PHP// Save the Verification code to the session for global use Session_Start (); $nums = ""; for ($i =0; $i 4; $i + +) {//generates a random number and converts it to a hexadecimal $nums. =dechex (Mt ...