Share a PHP verification code class (encapsulated as a class ). Copy the code as follows :? Phpsession_start (); Header (Content-type: imagegif); classSecurityCode {private $ codes; function _ construct () {$ code0-1-2-3-4-5-6-7-8-9-
The code is as follows:
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;
?>
After being encapsulated into a class, constructor is added for ease of use. You can also continue to improve the verification code class, such as adding destructor and saving memory.
The http://www.bkjia.com/PHPjc/323972.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323972.htmlTechArticle code is as follows :? 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 -...