Book Management system source code PHP generated random verification Code image code

Source: Internet
Author: User
Copy CodeThe code is as follows:


/** Default Home **/
Class Defaultcontroller extends AppController
{
Public Function index () {
$len = 5;
$str = "ABCDEFGHIJKLNMPQRSTUVWXYZ123456789";
$im = Imagecreatetruecolor (70, 20);
$BGC = Imagecolorallocate ($im, 255, 255, 255);
$bgtxt = Imagecolorallocate ($im, 220, 220, 220);
Random Palette
$colors = Array (
Imagecolorallocate ($im, 255, 0, 0),
Imagecolorallocate ($im, 0, 200, 0),
Imagecolorallocate ($im, 0, 0, 255),
Imagecolorallocate ($im, 0, 0, 0),
Imagecolorallocate ($im, 255, 128, 0),
Imagecolorallocate ($im, 255, 208, 0),
Imagecolorallocate ($im, 98, 186, 245),
);
Fill background color
Imagefill ($im, 0, 0, $BGC);
Get numbers randomly
$verify = "";
while (strlen ($verify) < $len) {
$i = strlen ($verify);
$random = $str [rand (0, strlen ($STR))];
$verify. = $random;
Draw background text
Imagestring ($im, 6, ($i *10) +3, rand (0,6), $random, $bgtxt);
Draw Main text information
Imagestring ($im, 6, ($i *10) +3, rand (0,6), $random, $colors [rand (0, COUNT ($colors)-1)]);
}
Add Random noise
for ($i =0; $i <100; $i + +) {
$color = Imagecolorallocate ($im, Rand (50,220), Rand (50,220), Rand (50,220));
Imagesetpixel ($im, Rand (0,70), Rand (0,20), $color);
}
Save verification Code in $_session
Sess ("verify", $verify);
Output a picture and release the cache
Header (' content-type:image/png ');
Imagepng ($im);
Imagedestroy ($im);
}
};
?>

The above introduces the book Management system source code PHP generated random verification code image code, including the book Management system source code aspects, I hope the PHP tutorial interested in a friend helpful.

  • 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.