Phpwind verification code

Source: Internet
Author: User
To support the. Image image function in the gd library, see php. liukang. commanualzhref. Image. php? PhpBYPHP country www. phphot. be disable error error_reporting (0); image width $ x_size60; image height $ y_size20; generate four random characters $ nmsgnum_rand (4); support secure connection? PHPwind verification code

The gd Library is required.
Image functions
See http://php.liukang.com/manual/zh/ref.image.php
// By php country www. phphot. be
// Close and report an error
Error_reporting (0 );
// Image width
$ X_size = 60;
// Image height
$ Y_size = 20;
// Generate 4 random characters
$ Nmsg = num_rand (4 );
// Is secure connection supported?
$ S = $ _ SERVER ['server _ port'] = '000000 '? 1:0;
// Use cookies to record random codes
// Expire = 0 cookie will expire after the session ends (usually closed by the browser.
SetCookie ('CK _ num', md5 ($ nmsg), 0, '/', ', $ S );
// Create an image (canvas) with a width of 60*20)
$ Aimg = imagecreate ($ x_size, $ y_size );
// Set the background color of the image
$ Back = imagecolorallocate ($ aimg, 255,255,255 );
// Set the font color
$ Border = imagecolorallocate ($ aimg, 0, 0, 0 );
// Fill in the white rectangle area of 59*19 from
Imagefilledrectangle ($ aimg, 0, 0, $ x_size-1, $ y_size-1, $ back );
// Draw a black rectangle border of 59*19 from
Imagerectangle ($ aimg, 0, 0, $ x_size-1, $ y_size-1, $ border );

For ($ I = 0; $ I
// Write on the image
ImageString ($ aimg, 5, $ I * $ x_size/4 + 3, 2, $ nmsg [$ I], $ border );
}
Header ("Content-type: image/png ");
Imagepng ($ aimg );
Imagedestroy ($ aimg); exit;
Function num_rand ($ lenth ){
// Play a random number generator seed
// Php starts from 4.2.0. this parameter becomes optional. If this parameter is null, it is set to the value at any time.
Mt_srand (double) microtime () * 1000000 );
// Generate a string with four random numbers
For ($ I = 0; $ I <$ lenth; $ I ++ ){
$ Randval. = mt_rand (0, 9 );
}
// Use md5 encryption for strings containing four digits. the length is 32 characters.
// From 3 to 32 characters, take the string with the length of $ lenth from the minimum number or the maximum number of 32-$ lenth
$ Randval = substr (md5 ($ randval), mt_rand (0, 32-$ lenth), $ lenth );
Return $ randval;
}
?>

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.