最简单的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



转载于:https://www.cnblogs.com/c3055/articles/2095969.html

你可能感兴趣的:(最简单的php验证码代码)