PHP image verification code production (medium ). Code for randomly generating numbers and letters :? Phpche. phpsession_start (); for ($ i0; $ i4; $ I ++) {$ rand. dechex (rand ();} $ _ SESSION [check_num] $ rand; $ imageimagecreatetruecolor (50 random numbers, letter code:
// Che. php
Session_start ();
For ($ I = 0; $ I <4; $ I ++)
{
$ Rand. = dechex (rand (1, 15 ));
}
$ _ SESSION ['Check _ num'] = $ rand;
$ Image = imagecreatetruecolor (50, 30 );
$ Bg = imagecolorallocate ($ im, 0); // specifies the background color when the palette is used for the first time.
$ Te = imagecolorallocate ($ im, 255,255,255 );
Imagestring ($ image, 6, rand (0, 20), rand (0, 2), $ rand, $ te );
Ob_clean (); // The Image "http: // localhost/**. PHP" is displayed on the php webpage because the verification code is generated.
Header ("Content-type: image/jpeg"); imagejpeg ($ image );
?>
Draw the interference line code for the image:
For ($ I = 0; $ I <8; $ I ++) // draw multiple lines
{
$ Cg = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); // Generate random colors
Imageline ($ im, rand (10, 40), 0, rand (10, 40), 20, $ cg );
}
Draw the interference point code for the image:
For ($ I = 0; $ I <80; $ I ++) // draw multiple points
{
Imagesetpixel ($ im, rand (0, 40), rand (0, 20), $ cg );
}
Write text into the image code:
$ Str = array ('my', 'my', 'login', 'login'); // store the displayed Chinese characters
For ($ I = 0; $ I <4; $ I ++)
{
$ Sss. = $ str [rand ()]; // randomly display Chinese characters
}
// $ Str = iconv ("gb2312", "UTF-8", $ str); // Chinese character encoding conversion, which does not seem to require me
Imagettftext ($ im, 10, 0, rand (5, 60), rand (5, 60), $ te, "simhei. ttf", $ sss );//
0: font skew. "simhei. ttf": font style, which is generally placed under the root directory;
From ms. RMB
Why :? Php // che. php session_start (); for ($ I = 0; $ i4; $ I ++) {$ rand. = dechex (rand ();} $ _ SESSION [check_num] = $ rand; $ image = imagecreatetruecolor (50...