ICE NoteBook
2008年8月1日 星期五
輕量的Pass_img程式
-- Chi_Passimg.php 程式碼如下 --- // 圖形驗証碼 By 二林網管 村仔 // 本程式獨立使用,呼叫時為
// 程式則產生圖形驗証碼,並將值寫在Session中 // 要檢驗時,只須將Session中存放的 $_session[Pass_img] 拿出來和您表單上的值核對即可
session_start(); $aa=new pass_img();//建立物件 $aa->show_str();//秀出驗証數字碼 class pass_img { var $pass; var $weight=70; var $height=24; function pass_img() { $t1=range('A', 'Z'); $t2=range(a,z); mt_srand((double)microtime()*1000000); $this->pass=$t1[mt_rand(0,25)].$t2[mt_rand(0,25)].sprintf("%04d",mt_rand(1,9999)); unset($_SESSION["Pass_img"]); session_register("Pass_img"); $_SESSION["Pass_img"]=$this->pass; } function show_str() { $size = "6"; // 字體大小0-6 $x = "5"; //字開頭 x 座標 $y = "3"; //字開頭 y 座標 $R = 255; //字的紅色值 $G = 15; //字的綠色值 $B = 15; //字的藍色值 $origImg = @imagecreate($this->weight,$this->height); $backgroundcolor = ImageColorAllocate($origImg,255,255,255); $textcolor = ImageColorAllocate ($origImg ,$R ,$G ,$B); Imagestring($origImg,$size,$x,$y,$this->pass,$textcolor); //加入干擾線(可不加) //Imageline($origImg,0,9,70,9,$textcolor); //x1,y1,x2,y2,color //加入干擾點(可不加) for($i=0;$i<100;$i++) { $randcolor = ImageColorallocate($origImg,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($origImg,rand()%$this->weight,rand()%$this->height,$randcolor); } //產生圖形 ImagePNG($origImg); ImageDestroy($origImg); } }
沒有留言:
張貼留言
‹
›
首頁
查看網路版
沒有留言:
張貼留言