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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值