Image Verification code problems? How can I use php code to generate random image verification codes? Please send the code. thank you !! ------ Solution -------------------- rand () GD ------ solution -------------------- & lt ;? Phpsession_start (); $ passwordmy_random_password (5); question about the image verification code?
How can I use php code to generate random image verification codes? Please send the code. thank you !!
------ Solution --------------------
Rand ()
GD
------ Solution --------------------
Session_start ();
$ Password = my_random_password (5 );
$ _ SESSION ["CheckCode"] = $ password;
Function my_random_password ($ length)
{
$ Result = "";
$ String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 ";
For ($ I = 0; $ I <$ length; $ I ++)
{
$ Result. = $ string [mt_rand (0, strlen ($ string)-1)];
}
Return $ result;
}
Header ("content-type: image/gif ");
// Initialize the image length and width
$ Image_x = $ _ GET ['width'];
$ Image_y = $ _ GET ['height'];
// Create an image
$ Image = imagecreate ($ image_x, $ image_y );
// Define the background color
$ Background_color = imagecolorallocate ($ image, 0xFF, 0xFF, 0xFF );
// Define the required color
$ Black_color = imagecolorallocate ($ image, 100, 50,255 );
$ Gray_color = imagecolorallocate ($ image, 0xdd, 0xdd, 0xdd );
// Generate Snow points cyclically
For ($ I = 0; I I <1000; $ I ++)
{
Imagesetpixel ($ image, mt_rand (0, $ image_x), mt_rand (0, $ image_y), $ gray_color );
}
// Input the random string into the image
// Imagestring ($ image, 8, 10, 3, $ password, $ black_color );
Imagettftext ($ image, 12, 0, 5, 17, $ black_color, './ariblk. ttf', $ password );
// Generate a rectangular border
Imagerectangle ($ image, 0, 0, $ image_x-1, $ image_y-1, $ black_color );
// Generate an image
Imagegif ($ image );
// Release the memory associated with $ image
Imagedestroy ($ image );
?>
------ Solution --------------------
See http://www.iebsoft.com/imall/system/login.php for the effect
------ Solution --------------------
Rand ()
GD programming ~