Copy CodeThe 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-f-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);
$testcolor 1 = imagecolorallocate ($img, 255,0,0);
$testcolor 2 = imagecolorallocate ($img, 51,51,51);
$testcolor 3 = imagecolorallocate ($img, 0,0,255);
$testcolor 4 = imagecolorallocate ($img, 255,0,255);
for ($i = 0; $i < 4; $i + +)
{
Imagestring ($img, Rand (5,6), 8 + $i * 15,rand (2,8), $this->codes[$i],rand (1,4));
}
Imagegif ($IMG);
}
}
$code = new Securitycode ();
$code->createimg ();
$code = NULL;
?>
After encapsulation into a class, the constructor is added, which makes it easier to use. You can also continue to refine the verification code class, such as adding destructors, how to save memory and so on.
The above describes the CF Brotherhood package verification Code, a PHP code share has been encapsulated into a class, including the CF Brotherhood package verification code aspects, I hope to be interested in PHP tutorial friends helpful.