php验证码
<?php session_start(); $rnd_code=4; for($i=0;$i<$rnd_code;$i++){ $nmsg .=dechex(mt_rand(0,15)); } $_SESSION["code"]=$nmsg; $width=75; $height=25; $img=imagecreatetruecolor($width,$height); $white=imagecolorallocate($img,255,255,255); imagefill($img,0,0,$white); //边框 $flag=false; if($flag){ $black=imagecolorallocate($img,0,0,0); imagerectangle($img,0,0,$width-1,$height-1,$black); } //随机线条 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,$height),mt_rand(0,$width),mt_rand(0,$height),$rnd_color); } //雪花 for($i=0;$i<100;$i++){ $rnd_color=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)); imagestring($img,1,mt_rand(1,$width),mt_rand(1,$height),'*',$rnd_color); } //生成随机验证码 for($i=0;$i<strlen($_SESSION['code']);$i++){ $rnd_color=imagecolorallocate($img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); imagestring($img,5,$i*$width/$rnd_code+mt_rand(1,10),mt_rand(1,$height/2),$_SESSION['code'][$i],$rnd_color); } header('Content-Type: image/png'); imagepng($img); imagedestroy($img); ?>