PHP Confirmation Code pictures (1)

Source: Internet
Author: User
Tags header integer rand

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);
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.