php 最简单的验证码
作者:jao 发布于:2012-12-16 0:30
分类:PHP教程
05 |
header(\"Content-type: image/png\"); |
07 |
$str = \"1,2,3,4,5,6,7,8,9,a,b,c,d,f,g\"; |
08 |
$list = explode (\",\", $str ); |
09 |
$cmax = count ( $list ) - 1; |
11 |
for ( $i =0; $i < 5; $i ++ ){ |
12 |
$randnum = mt_rand(0, $cmax ); |
13 |
$verifyCode .= $list [ $randnum ]; |
15 |
$_SESSION [ 'code' ] = $verifyCode ; |
17 |
$im = imagecreate(58,28); |
18 |
$black = imagecolorallocate( $im , 0,0,0); |
19 |
$white = imagecolorallocate( $im , 255,255,255); |
20 |
$gray = imagecolorallocate( $im , 200,200,200); |
21 |
$red = imagecolorallocate( $im , 255, 0, 0); |
22 |
imagefill( $im ,0,0, $white ); |
25 |
imagestring( $im , 5, 10, 8, $verifyCode , $black ); |
29 |
imagesetpixel( $im , rand()p , rand()0 , $black ); |
30 |
imagesetpixel( $im , rand()p , rand()0 , $red ); |
31 |
imagesetpixel( $im , rand()p , rand()0 , $gray ); |
40 |
<!-- DOCTYPE html PUBLIC \"- |
43 |
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> |
48 |
<form action=\"act.php\" method=\"post\"> |
49 |
<input type=\"text\" name=\"code\" /> |
50 |
<img id=\"code\" src=\"create_code.php\" alt=\"看不清楚,换一张\" style=\"cursor: pointer; vertical-align:middle;\" onClick=\"create_code()\"/> |
51 |
<!--<button type=\"button\" onClick=\"create_code()\">更换</button>--> |
52 |
<button type=\"submit\">提交</button> |
55 |
function create_code(){ |
56 |
document.getElementByIdx_x( 'code' ).src = 'create_code.php?' +Math.random()*10000; |
66 |
if ( $_POST [ 'code' ] == $_SESSION [ 'code' ]){ |
标签: php教程 PHP
et_highlighter