php如何使用随机函数rand()生成一个数字验证码?

php如何使用随机函数rand()生成一个数字验证码?


慕莱坞森
浏览 749回答 1
1回答

暮色呼如

参考这个$code="";//画布$image=imagecreatetruecolor(80, 25);imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));for($i=0;$i<4;$i++){ &nbsp; &nbsp;$rand_color=imagecolorallocate($image, rand(0,155), rand(0,155), rand(0,155)); &nbsp; &nbsp;$code_tmp=dechex(rand(1,15)); &nbsp; &nbsp;$code.=$code_tmp; &nbsp; &nbsp;imagestring($image, rand(4,5), rand($i*20,$i*20+20-6), rand(0,13),$code_tmp , $rand_color); &nbsp; &nbsp;//干扰线 &nbsp; &nbsp;imageline($image, rand($i*20,$i*20+20), rand(0,25), rand($i*20,$i*20+20), rand(0,25), $rand_color); &nbsp; &nbsp;imageline($image, rand($i*20,$i*20+20), rand(0,25), rand($i*20,$i*20+20), rand(0,25), $rand_color);}//保存session_start();$_SESSION['yzm']=$code;session_write_close();header("content-type:image/png");imagepng($image);imagedestroy($image);
打开App,查看更多内容
随时随地看视频慕课网APP