PHP Chinese character Verification Code program

Source: Internet
Author: User
The code is as follows Copy Code


<?php
/*
* File: chinesechar.php
* Role: Chinese character data storage
*/
$ChineseChar = Array ("Man", "Out", "Come", "friend", "Learn", "filial piety", "benevolence", "righteousness", "propriety," low "," Zhong "," Guo "," Zhong "," Yi "," white "," person "," Fire "," Earth "," gold "," Wood "," Thunder "," Wind "," Dragon " , "Tiger", "Day", "ground", "Sheng", "halo", "vegetable", "bird", "Tian", "three", "Hundred", "money", "Fu", "Love", "Love", "Beast", "Worm", "fish", "nine", "net", "new", "degree", "ay", "Alas", "ah", "Oh", "Miriam", "old", " Less "," Day "," month "," star ");
?>

<?php
/*
* File: check.php
* Role: Validation

*/
Session_Start ();
$errorMSG = ';
Verify that user input is consistent with the authentication code
if (!is_null ($_post[' check '))
{
if (strcasecmp ($_session[' code '],$_post[' Code ')) ==0)
$errorMSG = "<p style=" Font-size:12px;color: #009900 "> Validation Success!</p>";
Else
$errorMSG = "<p style=" Font-size:12px;color: #FF0000 "> Validation failure!</p>";
}
?>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<?php
if ($errorMSG) {
Echo $errorMSG;
}
?>
<form action=<?php echo $_server[' php_self ']?> method=post>
Please enter the verification code: <input type= "text" name= "code" style= "width:
80px ">
<br>
<input type= "Submit" name= "Check" value= "Submission Verification Code" >
</form>
</body>

<?php
/*
* File: code.php
* Function: Verify code generation

* Special Note: By the grass without teeth Guide Copyright reproduced Annotated source! There will be pay to reap!
*/
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, $fontcolor, $font, Iconv ("GB2312", "UTF-8", $text));

Output picture
Imagepng ($im);
Imagedestroy ($im);
?>

If you want to change the above program to English number, as long as in the chinesechar.php inside the array of Chinese into numbers or letters on the KO.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.