本文章来给大家介绍php生成雪花背景验证码程序代码,有需要的朋友可进入参考参考,验证码生成程序,代码如下:
- <?php
- session_start();
- session_register("login_check_number");
-
-
- $img_height=120;
- $img_width=40;
- if($HTTP_GET_VARS["act"]== "init"){
-
- for($Tmpa=0;$Tmpa<4;$Tmpa++){
- $nmsg.=dechex(rand(0,15));
- }
-
-
- $HTTP_SESSION_VARS[login_check_number] = $nmsg;
-
-
-
-
- $aimg = imageCreate($img_height,$img_width);
- ImageColorAllocate($aimg, 255,255,255);
- $black = ImageColorAllocate($aimg, 0,0,0);
- ImageRectangle($aimg,0,0,$img_height-1,$img_width-1,$black);
-
-
- for ($i=1; $i<=100; $i++) {
- imageString($aimg,1,mt_rand(1,$img_height),mt_rand(1,$img_width),"*",imageColorAllocate($aimg,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
-
- }
-
-
-
- for ($i=0;$i<strlen($HTTP_SESSION_VARS[login_check_number]);$i++){
- imageString($aimg, mt_rand(3,5),$i*$img_height/4+mt_rand(1,10),mt_rand(1,$img_width/2), $HTTP_SESSION_VARS[login_check_number][$i],imageColorAllocate($aimg,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
- }
- Header("Content-type: image/png");
- ImagePng($aimg);
- ImageDestroy($aimg);
- }
- ?>
验证测试页面,代码如下:
- <?php session_start();?>
- <FORM METHOD=POST ACTION="">
- <input type=text name=number maxlength=4><img src="YanZhengMa.php?act=init">
- <INPUT TYPE="submit" name="sub">
- </FORM>
- <?
-
- if(isset($HTTP_POST_VARS["sub"])):
- if($HTTP_POST_VARS["number"] != $HTTP_SESSION_VARS[login_check_number] || emptyempty($HTTP_POST_VARS["number"])){
- echo "校验码不正确!" ;
- }else{
- echo"验证码通过!";
- }
- endif;
- show_source('test.php');
-
-
-
-
- show_source('YanZhengMa.php');
- ?>
|