最简单的php验证码代码




1 show.php
2
3  <?php
4 session_start();
5 if($_POST[check]){
6
7 if($_POST[check]==$_SESSION[check_pic]){
8 echo "验证码正确".$_SESSION[check_pic];
9 }
10 else {
11 echo "验证码错误".$_SESSION[check_pic];
12 }
13 }
14
15
16  ?>
17  <form action="" method="post">
18  <img src="checkTest.php" /><br />
19  <input name="check" type="text" /><br />
20 <input name="" type="submit" value="提交"/>
21 </form>

check.php
<?php

session_start();
for($i=0;$i<4;$i++)
{
$rand.= dechex(rand(1, 15));

}
$_SESSION[check_pic]=$rand;

$im=imagecreatetruecolor(100, 30);

//set color
$bg=imagecolorallocate($im, 0, 0,0);//background color
$te=imagecolorallocate($im, 255, 255, 255);

for($i=0;$i<3;$i++){
$te2=imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
//set line
imageline($im, rand(0,100), 0, 100, 30, $te2);
}
for($i=0;$i<200;$i++){
imagesetpixel(
$im, rand()%100, rand()%30, $te2);

}

$str=iconv("gbk", "UTF-8", "显示UTF-8");
imagettftext(
$im, 14,9,20,20,$te,'CHILLER.TTF', $str);

//
//imagestring($im, rand(1, 6),rand(3, 70), rand(0, 15), $rand, $te);

//show

header("Content-type:image/jpeg");
imagejpeg(
$im);


?>

show.php



posted @ 2011-07-01 22:43  Credo Chen  阅读(886)  评论(0编辑  收藏  举报
无觅相关文章插件,快速提升流量