PHP seven different types of personalized creative Verification code examples

Source: Internet
Author: User

Verification Code picture HTML code:


The first image authentication code class, the other 6 kinds of authentication code class please download view:

Class captcha{
/**
+----------------------------------------------------------
* Generate Verification Code
+----------------------------------------------------------
* @static
* @access Public
+----------------------------------------------------------
* @param int $len Verification Code character number
* @param int $font _size Verification code font size
* @param string $name session Name
* @param int $width picture length
* @param int $height picture height
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
static function Generate ($len =4, $font _size=48, $name = ' captcha ', $width = ', $height = ') {
if ($width = = ") $width = ($font _size+5) * ($len + 1);
if ($height = = ") $height = ($font _size) *2;
$chars = ' bcdefhkmnrstuvwxyABCDEFGHKMNPRSTUVWXY345689 ';
$str = ';
for ($i =0; $i < $len; $i + +) {
$str. = substr ($chars, Mt_rand (0,strlen ($chars)-1), 1);
}
$_session[$name]= $str;//write session
For ($num =0 $num <10; $num + +) {
Ob_start ();
$image =imagecreatetruecolor ($width, $height);//Create Picture
$BG _color=imagecolorallocate ($image, 255,255,255);//Set Background color
$border _color=imagecolorallocate ($image, 100,100,100);//Set Border color
$text _color=imagecolorallocate ($image, 0,0,0);//Set the authentication code color
Imagefilledrectangle ($image, 0,0, $width-1, $height-1, $BG _color);//Fill picture background color
Imagerectangle ($image, 0,0, $width-1, $height-1, $border _color);//Fill picture border color
For ($i =0 $i <5; $i + +) {
$line _color=imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255));/Interference Line Color
Imageline ($image, rand (0, $width), 0, $width, $height, $line _color);/Draw a line segment
}
For ($i =0 $i <500; $i + +) {
$dot _color=imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255));/Interference point color
Imagesetpixel ($image, rand ()% $width, rand ()% $height, $dot _color);/Draw a pixel.
}
for ($i =0; $i < $len; $i + +) {
Imagettftext ($image, $font _size,rand ( -3,3), $font _size/2+ ($font _size+5) * $i, $height/1.25-rand (2,3), $text _color, ' Groupsex.ttf ', $str [$i]);//write text to image in specified font
}
Imagegif ($image);
Imagedestroy ($image);
$imagedata [] = Ob_get_contents ();
Ob_clean ();
}
Require (' GIFEncoder.class.php ');
$gif = new Gifencoder ($imagedata);
Ob_clean ()//To prevent the "image because its own error can not be displayed" problem
Header (' content-type:image/gif ');
echo $gif->getanimation ();
}
}
Call Example
Session_Start ();
Captcha::generate (6,48);

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.