Session_Start ();//number of random codes//$_rnd_code = 4;//Create random code for ($i =0; $i <4; $i + +) {$_nmsg.=dechex (Mt_rand (0,15));} Save session$_session[' code ']=$_nmsg;//long and high $_width = 75;$_height = 25;//Create an image $_img = Imagecreatetruecolor ($_width,$_ height);//Output Image header (' content-type:image/png '); Imagepng ($_img);
The output result is
Reply to discussion (solution)
$_nmsg= ";
for ($i =0; $i <4; $i + +) {
$_nmsg.=dechex (Mt_rand (0,15));
}
$_nmsg= ";
for ($i =0; $i <4; $i + +) {
$_nmsg.=dechex (Mt_rand (0,15));
}
Session_Start ();//number of random code//$_rnd_code = 4;$_nmsg= ";//create Random code for ($i =0; $i <4; $i + +) {$_nmsg.=dechex (Mt_rand (0,15));} Save session$_session[' code ']=$_nmsg;//long and high $_width = 75;$_height = 25;//Create an image $_img = Imagecreatetruecolor ($_width,$_ height);//White $_white = Imagecolorallocate ($_img,255,255,255);//Fill Imagefill ($_img,0,0,$_white); $_flag = False;if ($_ Flag) {//black border $_black = Imagecolorallocate ($_img,0,0,0); Imagerectangle ($_img,0,0,$_width-1,$_height-1,$_black);} 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,$_height), Mt_rand (0,$_width), Mt_rand (0,$_height), $_rnd_ color);} Random snowflake 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);} Output Verification Code for ($i =0; $i
After writing, it still shows
Notice: Undefined variable: _rnd_code inD:\AMP\web\ide_tmp.phpOn line -
Warning: Division by zero inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _heght inD:\AMP\web\ide_tmp.phpOn line -
Warning: Mt_rand (): Max (0) is smaller than min (1) inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _rnd_code inD:\AMP\web\ide_tmp.phpOn line -
Warning: Division by zero inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _heght inD:\AMP\web\ide_tmp.phpOn line -
Warning: Mt_rand (): Max (0) is smaller than min (1) inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _rnd_code inD:\AMP\web\ide_tmp.phpOn line -
Warning: Division by zero inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _heght inD:\AMP\web\ide_tmp.phpOn line -
Warning: Mt_rand (): Max (0) is smaller than min (1) inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _rnd_code inD:\AMP\web\ide_tmp.phpOn line -
Warning: Division by zero inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _heght inD:\AMP\web\ide_tmp.phpOn line -
Warning: Mt_rand (): Max (0) is smaller than min (1) inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _rnd_code inD:\AMP\web\ide_tmp.phpOn line -
Warning: Division by zero inD:\AMP\web\ide_tmp.phpOn line -
Notice: Undefined variable: _heght inD:\AMP\web\ide_tmp.phpOn line -
Warning: Mt_rand (): Max (0) is smaller than min (1) inD:\AMP\web\ide_tmp.phpOn line -
‰png
Modify by error message
Then you have to:
Still unfriendly "captcha" picture
Comment out the header and open the error to see the error.