PHP generated Chinese Verification Code program

Source: Internet
Author: User
Tags rand strlen

<?php
Session_Start ();
# get random characters
function Getrandstr ($length = 4, $mode = 1)
{
$str 1 = ' 123456789 ';
$str 2 = ' abcdefghijklmnopqrstuvwxyz ';
$str 3 = ' abcdefghijklmnpqrstuvwxyz ';
$str 4 = ' _ ';
$str 5 = ' ~!@#$%^&* ()-+=\| {}[];:'",./?';
$str 6 = ' Jihai, don't give the Japanese any chance. Great China Right-back he inherits the glorious tradition of the Chinese nation Dongcunrui Huang Jiguang autumn Little cloud at this moment the soul protrusions Jihai A man he represents the long tradition of Chinese football in this moment he is not a man of the fight he's not alone. Liyi the emperor face the penalty, he faces the eyes and expectations of the Chinese fans all over the world. Cks can live once in the supplementary game of the World Cup caucuses in the additional game to throw out countless penalties the great must know that he can still smile to face the person in front of him? What's he going to be after the second? The Chinese team won the victory of the Japanese team they did not once again to the great Chinese team of the People's Republic of China in front of Zico Right back Kitty today Happy birthday to the People's Republic of China Long live the Japanese team may regret Zico he played too conservatively in the second half, and he lost himself. The courage to face the long history and tradition of Chinese football he didn't hit the goalkeeper like he did in a group game. They should go home. They don't have to go back to Japan because they Will choose collective Caesarean section suicide goodbye ';

Switch ($mode)
{
Case ' 0 ':
$str = $str 1. $str 2. $str 3. $STR 4;
Break

Case ' 1 ':
$str = $str 1;
Break

Case ' 2 ':
$str = $str 2;
Break

Case ' 3 ':
$STR = $str 3;
Break

Case ' 4 ':
$str = $str 2. $str 3;
Break

Case ' 5 ':
$str = $str 1. $str 2;
Break

Case ' 6 ':
$str = $str 1. $str 3;
Break

Case ' 7 ':
$str = $str 1. $str 2. $str 3;
Break

Case ' 8 ':
$str = $str 1. $str 2. $str 3. $str 4. $str 5;
Break
Case ' 9 ':
$str = $str 6;
Break
Default:
$str = $str 1. $str 2. $str 3. $STR 4;
Break
}

$result = "";

if ($mode ==9)
{
$tmp 1 = $length/2;
$tmp = Explode (".", strlen ($STR)/2);
for ($i = 0; $i < $tmp 1; $i + +)
{
$result. = Substr ($str, Mt_rand (0, $tmp [0]) *2-$length, 2);
}
}
Else
{
for ($i = 0; $i < $length; $i + +)
{
$result. = $str [Mt_rand (0, strlen ($str)-1)];
}
}
return $result;
}

##
# Generate CAPTCHA Picture
#
function createauthnumimg ($randStr, $isGB =false)
{
Header ("Content-type:image/png");

$im = Imagecreate (50,20);
$black = Imagecolorallocate ($im, 0,0,0);
$white = Imagecolorallocate ($im, 255,255,255);
$gray = Imagecolorallocate ($im, 0,100,150);
Imagefill ($im, 50,19, $gray);

For ($i =0 $i <80; $i + +) # Add interference pixels
{
$randcolor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, Rand ()%50, Rand ()%19, $randcolor);
}

if ($isGB!=false) # using Chinese verification Code
{
Require_once ("GB2312toUTF8.inc.php");
$GB 2312toUTF = new Gb2312toutf8 ();
Imagettftext ($im, 5, 5, $white, "SIMSUN.TTC", $GB 2312toutf->gb2utf8 ($RANDSTR));
}
else Imagestring ($im, 8, 8, 3, $RANDSTR, $white); # Draw the validation code into the picture

Imagepng ($im);
Imagedestroy ($im);

$_session[' chknum ' = $randStr; # Save Verification Code
}
$m =$_get["M"];
if (empty ($m)) {
$m = 9;
}
Createauthnumimg (Getrandstr ("6", $m), 1)
?>

Related Article

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.