allen
          專注于java ee技術(shù),包括struts,jsf,webwork,spring,hibernate,ibatis
          posts - 7,  comments - 9,  trackbacks - 0
          因?yàn)榉乐箰阂庠u(píng)論,所以要求加個(gè)驗(yàn)證碼,要求簡(jiǎn)單,一般的20以內(nèi)的加法即可,根據(jù)其它網(wǎng)上的驗(yàn)證碼,修改了下:
          <?php 
          //session_start();
          //生成驗(yàn)證碼圖片 
          Header("Content-type: image/PNG"); 
          srand((double)microtime()*1000000);//播下一個(gè)生成隨機(jī)數(shù)字的種子,以方便下面隨機(jī)數(shù)生成的使用
          //session_start();//將隨機(jī)數(shù)存入session中
          $_SESSION['authnum']="";
          $im = imagecreate(70,20) or die("Cant's initialize new GD image stream!"); //制定圖片背景大小
          $black = ImageColorAllocate($im, 0,0,0); //設(shè)定三種顏色
          $white = ImageColorAllocate($im, 255,255,255); 
          $gray = ImageColorAllocate($im, 200,200,200);
          imagefill($im,0,0,$gray); //采用區(qū)域填充法,設(shè)定(0,0)
          //生成數(shù)字和字母混合的驗(yàn)證碼方法
          //$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
          $ychar="0,1,2,3,4,5,6,7,8,9";
          $list=explode(",",$ychar);
          $answer='';
          $authnum=0;
          for($i=0;$i<2;$i++){
          $randnum=rand(0,10);
          $authnum=$authnum+intval($randnum);
          error_log("auth:$authnum :dddd:$randnum",0);
          $answer=$answer.intval($randnum)."+";
          }
          $answer=rtrim($answer,"+");
          $answer=$answer.'=?';
          //$authnum=''.$answer;
          //while(($authnum=rand()%100000)<10000); //生成隨機(jī)的五們數(shù)
          //將五位整數(shù)驗(yàn)證碼繪入圖片 
          //$_COOKIE['authnum']=$authnum;
          //error_log("auth:$authnum",0);
          setCookie("authnum",$authnum,null,'/');
          //imagestring($im, 5, 10, 3, $authnum, $black);
          imagestring($im, 5, 10, 3, $answer, $black);
          // 用 col 顏色將字符串 s 畫到 image 所代表的圖像的 x,y 座標(biāo)處(圖像的左上角為 0, 0)。
          //如果 font 是 1,2,3,4 或 5,則使用內(nèi)置字體
          /*
          for($i=0;$i<200;$i++) //加入干擾象素 
          $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
          imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); 
           
           */
          ImagePNG($im); 
          ImageDestroy($im);

          posted on 2011-12-12 10:17 robbin163 閱讀(1155) 評(píng)論(0)  編輯  收藏 所屬分類: WEB MVC

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 全州县| 兰西县| 南开区| 方城县| 平远县| 德保县| 大邑县| 彭阳县| 阿坝| 酒泉市| 横峰县| 澄城县| 松溪县| 洱源县| 河西区| 五大连池市| 大足县| 紫云| 托里县| 涞源县| 柯坪县| 汕尾市| 铜陵市| 手游| 淮安市| 阿克苏市| 金堂县| 南康市| 曲麻莱县| 马关县| 绥芬河市| 克拉玛依市| 绥阳县| 凤城市| 东兰县| 丹巴县| 安国市| 右玉县| 中方县| 隆德县| 凤山市|