This article uses three files to briefly talk about how to apply Chinese verification codes in PHP. Because Chinese characters may appear garbled, we have defined a file to handle them specifically. Friends in need can refer to it. .
The code is as follows | Copy code |
/* */ Verification successful! ";$errorMSG = " Verification failed! ";} ?> if($errorMSG){ echo $errorMSG; } ?> /* * File:code.php * Function: Verification code generation * Special note: Directed by Toothless Grass. All rights reserved. Please indicate the source when reprinting! Only by giving will you gain! */ include_once("chinesechar.php"); session_start(); // Set content-type header("Content-type: image/png"); //Create image $im = imagecreatetruecolor(120, 30); //Create color
$fontcolor = imagecolorallocate($im, 255, 255, 255); //Set text $_SESSION['code'] = $text; //Add text //Output image |
If you want to change the above program to English numbers, just change the Chinese array in chinesechar.php to numbers or letters and it will be KO.