allen
          專注于java ee技術(shù),包括struts,jsf,webwork,spring,hibernate,ibatis
          posts - 7,  comments - 9,  trackbacks - 0
          因為防止惡意評論,所以要求加個驗證碼,要求簡單,一般的20以內(nèi)的加法即可,根據(jù)其它網(wǎng)上的驗證碼,修改了下:
          <?php 
          //session_start();
          //生成驗證碼圖片 
          Header("Content-type: image/PNG"); 
          srand((double)microtime()*1000000);//播下一個生成隨機數(shù)字的種子,以方便下面隨機數(shù)生成的使用
          //session_start();//將隨機數(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ù)字和字母混合的驗證碼方法
          //$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); //生成隨機的五們數(shù)
          //將五位整數(shù)驗證碼繪入圖片 
          //$_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 座標處(圖像的左上角為 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) 評論(0)  編輯  收藏 所屬分類: WEB MVC

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           

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

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 安阳市| 六盘水市| 阿图什市| 蓬莱市| 泉州市| 都昌县| 梅河口市| 维西| 阳江市| 紫云| 巴青县| 新竹县| 乌苏市| 湘西| 盐池县| 巫山县| 大竹县| 衡东县| 井冈山市| 大宁县| 沐川县| 福清市| 静宁县| 乐安县| 贵定县| 屏南县| 九龙县| 吉木乃县| 勃利县| 鹤庆县| 抚远县| 平原县| 环江| 旅游| 黄骅市| 桓台县| 柘城县| 溆浦县| 武鸣县| 齐河县| 合阳县|