PHP Verification Code Function module

Source: Internet
Author: User

<?php
Session_Start ();
function Random ($len) {
$srcstr = ' 0123456789asdfghjklzxcvbnmqwertyuiop ';
Mt_srand ();
$strs = "";
for ($i =0; $i < $len; $i + +) {
$strs. = $srcstr [Mt_rand (0,30)];
}
return $strs;
}
Randomly generated string
$str =random (4);

Verify the width of the code picture
$width = 80;

Verify the height of the code picture
$height = 40;

Declare the picture format of the layer you want to create
@header ("Content-type:image/png");

Create a layer
$im =imagecreate ($width, $height);

Background color
$back =imagecolorallocate ($im, 255,255,255);

Blur Point Color
$pix =imagecolorallocate ($im, 187,230,247);

Font Color
$font =imagecolorallocate ($im, 41,163,238);

Plot Blur points
Mt_srand ();
for ($i =0; $i <1000; $i + +)
{
Imagesetpixel ($im, Mt_rand (0, $width), Mt_rand (0, $height), $pix);
}

Output character
Imagestring ($im, 5,25,10, $str, $font);


Output layer
Imagepng ($im);
?>

Reference article: http://www.jb51.net/article/51506.htm

PHP Verification Code Function module

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.