前端頁面index.php
創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的綿竹網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
'; }else{ echo '輸入不對
'; } } ?>
生成驗(yàn)證碼圖片test.php
服務(wù)器自己的空間保存一份 $_SESSION['code'] = $vcode->getCode(); //將驗(yàn)證碼的圖片輸出 $vcode->outimg();//調(diào)用方法
驗(yàn)證碼類 print.php
width = $width; $this->heigth = $height; $this->num = $num; $this->code = $this->createCode(); } //獲取字符的驗(yàn)證碼 function getCode(){ return $this->code; } //輸出驗(yàn)證碼圖形 function outimg(){ //創(chuàng)建背景 顏色 大小 邊框 $this->createBack(); //畫字 大小 字體顏色 $this->outString(); //干擾元素 點(diǎn) 線條 $this->setDisturb(); //輸出圖像 $this->printImg(); } //創(chuàng)建背景 private function createBack(){ //創(chuàng)建資源 $this->img = p_w_picpathcreatetruecolor($this->width, $this->heigth); //設(shè)置隨機(jī)背景顏色 $bgcolor = p_w_picpathcolorallocate($this->img, rand(225, 255), rand(225, 255), rand(225, 255)); //填充背景色 p_w_picpathfill($this->img, 0, 0, $bgcolor); //畫矩形 $bordercolor = p_w_picpathcolorallocate($this->img, 0, 0, 0); p_w_picpathrectangle($this->img, 0, 0, $this->width-1, $this->heigth-1, $bordercolor); } //畫字 private function outString(){ for($i=0;$i<$this->num;$i++){ $color = p_w_picpathcolorallocate($this->img, rand(0, 128), rand(0, 128), rand(0, 128)); $font = rand(3,5); $x = 3 + ($this->width/$this->num)*$i; $y = rand(1, 5); p_w_picpathstring($this->img, $font,$x, $y, $this->code{$i}, $color); } } //設(shè)置干擾元素 private function setDisturb(){ //加上點(diǎn)數(shù) for($i=0;$i<100;$i++){ $color = p_w_picpathcolorallocate($this->img, rand(0, 255), rand(0, 255), rand(0, 255)); p_w_picpathsetpixel($this->img, rand(1, $this->width-2), rand(1, $this->heigth-2), $color); } //加上線條 for($i=0;$i<10;$i++){ $color = p_w_picpathcolorallocate($this->img, rand(0, 255), rand(0, 128), rand(0, 255)); p_w_picpatharc($this->img, rand(-10, $this->width+10), rand(-10, $this->heigth+10), rand(30, 300), rand(30, 300), 55, 44, $color); } } //輸出圖像 private function printImg(){ // header("Content-Type:p_w_picpath/jpeg"); // p_w_picpathjpeg($this->img); if(p_w_picpathtypes() & IMG_GIF){ header("Content-Type:p_w_picpath/gif"); p_w_picpathjpeg($this->img); }elseif(p_w_picpathtypes() & IMG_JPEG){ header("Content-Type:p_w_picpath/jpeg"); p_w_picpathjpeg($this->img); }elseif(p_w_picpathtypes() & IMG_JPG){ header("Content-Type:p_w_picpath/jpg"); p_w_picpathjpeg($this->img); }elseif(p_w_picpathtypes() & IMG_PNG){ header("Content-Type:p_w_picpath/png"); p_w_picpathjpeg($this->img); } } //生成驗(yàn)證碼 private function createCode(){ $codes = "23456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; $code = ""; for($i=0;$i<$this->num;$i++){ $code .=$codes{rand(0,strlen($codes)-1)}; } return $code; } //釋放圖像資源 function __destruct(){ p_w_picpathdestroy($this->img); } }