Confirmation code generation file checknum_session.php
?
Header ("Content-type:image/png");
Define header, declare picture file, preferably PNG, no copyright disturbance;
To generate a new four-bit integer verification code
Session_Start ()//open session;
$authnum _session = ';
$str = ' abcdefghijkmnpqrstuvwxyz1234567890 ';
Define the numbers and letters to be displayed on the picture;
$l = strlen ($STR); Gets the length of the string;
The loop randomly extracts the four-bit previously defined letters and numbers;
For ($i =1 $i <=4; $i + +)
{
$num =rand (0, $l-1);
Randomly extract one digit at a time, from the first word to the maximum length of the string,
Minus 1 is because the Intercept character starts at 0, so that 34 characters may be in the line.
$authnum _session.= $str [$num];
will be through the number of words Fulianqi to a total of four bits;
}
Session_register ("Authnum_session");
Use the session to do verification is also good; Register session, name is Authnum_session,
Other pages just include the picture
That is, you can call it by $_session["Authnum_session"]
Generate a Captcha picture,
Srand (Double) microtime () *1000000);
$im = Imagecreate (50,20);//Picture wide and high;
Mainly used in black and white gray three kinds of color;
$black = Imagecolorallocate ($im, 0,0,0);
$white = Imagecolorallocate ($im, 255,255,255);
$gray = Imagecolorallocate ($im, 200,200,200);
To draw a four-bit integer verification code into a picture
Imagefill ($im, 68,30, $gray);
If you do not need to disturb the line, comments on the line;
$li = Imagecolorallocate ($im, 220,220,220);
For ($i =0 $i <3; $i + +)
{//Add 3 interference lines; it may not, depending on the circumstances, because it may affect user input;
Imageline ($im, Rand (0,30), Rand (0,21), Rand (20,40), Rand (0,21), $li);
}
character in the position of the picture;
Imagestring ($im, 5, 8, 2, $authnum _session, $white);
For ($i =0 $i <90; $i + +)
{//Add interference pixels
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $gray);
}
Imagepng ($im);
Imagedestroy ($im);
?>