Home  >  Article  >  Backend Development  >  PHP Chinese character verification code program_PHP tutorial

PHP Chinese character verification code program_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:10:191083browse

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


/* 
* File: chinesechar.php
* Function: Chinese character data storage
*/ 
$ChineseChar = array("人","出","来","友","学","filial piety","benevolence","righteousness","property","honesty","loyalty"," "Guo", "Zhong", "Yi", "White", "Zhe", "Fire", "Earth", "Gold", "Wood", "Thunder", "Wind", "Dragon", "Tiger" ,"Heaven","Earth", "生"," faint","vegetable","bird","field","three","hundred","money","blessing","love"," "love", "beast", "worm", "fish", "nine", "net", "new", "degree", "ah", "ala", "ah", "oh", "yi" , "老", "小", "日", "月", "星");
?>

/* 
* File: check.php
* Function: Verification

*/ 
session_start();
$errorMSG = '';
//Verify whether the user input is consistent with the verification code
if(!is_null($_POST['check']))
{ 
If (strcasecmp($_SESSION['code'],$_POST['code'])==0)
                $errorMSG = "

Verification successful!

"; 
                                                                                                           $errorMSG = "

Verification failed!

"; 

?>





if($errorMSG){
echo $errorMSG;

?>
method=post> 
Please enter the verification code:






/* 
* 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);
$bg = imagecolorallocate($im, 0, 0, 0);

//Set text
for($i=0;$i<4;$i++) $text .= $ChineseChar[(array_rand($ChineseChar))];

$_SESSION['code'] = $text;
// Set font
$font = 'simkai.ttf';

//Add text
imagettftext($im, 18, 0, 11, 21, $fontcolor, $font, iconv("GB2312","UTF-8",$text));

//Output image
imagepng($im);
imagedestroy($im);
?>

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629692.htmlTechArticleThis article uses three files to briefly talk about how to apply Chinese verification codes in php. Because Chinese Chinese characters may appear garbled, so we defined a file to deal with it specifically...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn