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 );
?>