Two php code for generating a graphic Verification Code

Source: Internet
Author: User

Verification codes are often used in php. Below we provide you with some classes and programs for generating php verification codes. You can directly use them by copying them. Let's look at the code below.

The verification code is often used in php tutorials. Below we provide you with some php verification code generation classes and programs, which can be directly used by directly copying them. Let's look at the code below.

<? Php
Session_start ();
Header ("Content-type: image/gif ");
Class SecurityCode
{
Private $ codes = '';
Function _ construct ()
{
$ Code = '0-1-2-3-4-5-6-7-8-9-a-b-c-d-e-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z ';
$ CodeArray = explode ('-', $ code );
Shuffle ($ codeArray );
$ This-> codes = implode ('', array_slice ($ codeArray, 0, 4 ));
}
Public function CreateImg ()
{
$ _ SESSION ['check _ pic '] = $ this-> codes;
$ Img = imagecreate (70, 25 );
Imagecolorallocate ($ img, 222,222,222 );
$ Testcolor1 = imagecolorallocate ($ img, 255, 0, 0 );
$ Testcolor2 = imagecolorallocate ($ img, 51,51, 51 );
$ Testcolor3 = imagecolorallocate ($ img, 255 );
$ Testcolor4 = imagecolorallocate ($ img, 255, 0, 255 );
For ($ I = 0; $ I <4; $ I ++)
{
Imagestring ($ img, rand (), 8 + $ I * 15, rand (), $ this-> codes [$ I], rand ));
}
Imagegif ($ img );
}
}
$ Code = new SecurityCode ();
$ Code-> CreateImg ();
$ Code = NULL;
?>

Code 2

 

<?
Session_start ();
For ($ I = 0; $ I <4; $ I ++ ){
$ Rand. = dechex (rand (1, 15 ));
}
$ _ SESSION [check_pic] = $ rand;
// Echo $ _ SESSION [check_pic];
// Set the image size "> image size
$ Im = imagecreatetruecolor (100,30 );
// Set the color
$ Bg = imagecolorallocate ($ im, 0, 0 );
$ Te = imagecolorallocate ($ im, 255,255,255 );
// Write the string in the upper left corner of the image
Imagestring ($ im, rand (5, 6), rand (25, 30), 5, $ rand, $ te );
// Output image
Header ("Content-type: image/jpeg ");
Imagejpeg ($ im );
?>

Related Article

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.