show.php
@session_start();
if(empty($_POST)){
echo "";
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;
}
}
?>