File a.php
//checkNum.php
session_start();
function random($len)
{
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand() ;
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
return strtoupper($strs);
}
$str=random(4); //Randomly generated string
$width = 50; //Width of verification code image
$height = 25; //Height of verification code image
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
// echo $str;
$im=imagecreate($width,$height);
//Background color
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//Blurred Point color
$pix=imagecolorallocate($im,187,230,247);
//Font color
$font=imagecolorallocate($im,41,163,238);
//Plot blur effect point
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height), $pix);
}
imagestring($im, 5, 7, 5,$str, $font);
imagerectangle($im,0,0,$width-1,$height-1 ,$font);
imagepng($im);
imagedestroy($im);
$_SESSION["code"] = $str;
?>
File b.php
session_start();
echo "";//Generate image
echo $_SESSION["code" ];//Generate verification code value
?>