|
/*
* File: chinesechar.php
* Role: Chinese character data storage
*/
$ChineseChar = Array ("Person", "out", "Come", "friend", "Learn", "filial piety", "benevolence", "righteousness", "propriety", "low", "loyalty", "Country", "middle", "easy", "white", "person", "Fire", "Earth", "gold", "Wood", "Thunder", "Wind", "Dragon" , "Tiger", "Day", "ground", "Life", "halo", "dish", "bird", "Tian", "three", "Hundred", "money", "blessing", "Love", "Feeling", "Beast", "Worm", "fish", "nine", "net", "new", "degree", "ay", "Alas", "ah", "Oh", "Miriam", "old", " Less "," Day "," month "," star ");
?>
/*
* File: check.php
* Role: Validation
*/
Session_Start ();
$errorMSG = ";
Verify that the user input is consistent with the verification code
if (!is_null ($_post[' check '))
{
if (strcasecmp ($_session[' code '],$_post[' code ') ==0)
$errorMSG = "
Verify success!
";
Else
$errorMSG = "
Validation failed!
";
}
?>
if ($errorMSG) {
Echo $errorMSG;
}
?>
/*
* File: code.php
* Function: Verification code generation
* Special Note: By the teeth of the Grass guide all copyright reprint to indicate the source! There will be a harvest to pay!
*/
Include_once ("chinesechar.php");
Session_Start ();
Set Content-type
Header ("Content-type:image/png");
Create a picture
$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, 0, one, one, $fontcolor, $font, Iconv ("GB2312", "UTF-8", $text));
Output picture
Imagepng ($im);
Imagedestroy ($im);
?>
|