php mysql 验证码,汉字验证码 - PHP/MySQL - 忘情森林's Blog

show.php

@session_start();

if(empty($_POST)){

 echo "create.php";

echo "

 ";

}else{

$ichinese = $_POST['ichinese'];

if($ichinese != $_SESSION['chinese']){

echo "";

}else{

echo "";

}

}

?>

create.php

require_once 'gb2utf8.php';

@session_start();

@session_register("chinese");

$code = new createchar;

$result1 = $code->getcode(1);

$result2 = $code->getcode(2);

$result3 = $code->getcode(3);

$result4 = $code->getcode(4);

$string1 = "%".$result1.$result2."%".$result3.$result4;

$string2 = "%".$result1.$result3."%".$result3.$result4;

$string3 = "%".$result1.$result4."%".$result3.$result4;

$hanzi1 = urldecode($string1);

$hanzi2 = urldecode($string2);

$hanzi3 = urldecode($string3);

$hanzi = $hanzi1.$hanzi2.$hanzi3;

$_SESSION['chinese'] = $hanzi;

Header("Content-type: image/png");

$im = imagecreate(150,40);

$black = ImageColorAllocate($im, 0,0,0);

$red = ImageColorAllocate($im, 184,44,6);

$gray = ImageColorAllocate($im, 200,200,200);

imagefill($im,80,38,$gray);

$obj=new gb2utf8();

$obj->gb = $hanzi1;

$obj->Convert();

ImageTTFText($im, rand(12,22), rand(-45,45), 20, 30, $red, "SIMKAI.TTF", $obj->utf8);

$obj->gb = $hanzi2;

$obj->Convert();

ImageTTFText($im, rand(12,22), rand(-45,45), 60, 30, $red, "SIMKAI.TTF", $obj->utf8);

$obj->gb = $hanzi3;

$obj->Convert();

ImageTTFText($im, rand(12,22), rand(-45,45), 100, 30, $red, "SIMKAI.TTF", $obj->utf8);

for($i = 0;$i < 300;$i++){   //加入干扰象素

imagesetpixel($im, rand()%150 , rand()%40 , $black);

}

ImagePNG($im);

ImageDestroy($im);

class createchar{

function getcode ($mode = 1){

switch ($mode) {

case '1':

$str = 'BC';

$num = 1;

break;

case '2':

$str = '0123456789ABCDEF';

$num = 15;

break;

case '3':

$str = 'ABCDEF';

$num = 5;

break;

case '4':

$str = '123456789ABCDE';

$num = 3;

break;

}

$randnum = rand(0,$num);

$result = $str[$randnum];

return $result;

}

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值