国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP編寫驗(yàn)證碼時(shí),線上程式碼編輯器能夠顯示,放在本地網(wǎng)站上就亂碼了?
phpcn_u53259
phpcn_u53259 2017-11-06 13:50:30
0
9
1329

<?php

??

? ?check_code();

? ?

? //隨機(jī)產(chǎn)生驗(yàn)證碼的字元或數(shù)字

? ?function check_code($width=100, $height=50,$num=4, $type='jpeg')

? ?{

#? ? ? ?$i=imagecreate($width,$height) ;

? ? ? ?$string='';

? ? ? ?for($j=0;$j<$num;$j )

? ? ??{##?#. =mt_rand(0,2);

? ? ? ? ? ?switch($rand)

? ? ? ? ? ?{

? ?? $? ? ? ?{

? ?ascii=mt_rand(48,57) ;

? ? ? ? ? ? ? ?break;

? ? ? ? ? ? case 1:

? ? ?? _?? ? ? ?break;

? ? ? ? ? ? case 2 :

? ? ? ? ? ? ? ?$ascii=mt_rand(97,122);

? ? ? ? ? ? ??#; ing.=sprintf('%c' ,$ascii) ;//ascii字元解碼

? ? ? ?}

#? ?

//產(chǎn)生驗(yàn)證碼背景顏色(randbg():函數(shù)呼叫)

? ?

##imagefilledrectangle($i,0,0,$width,$height,randbg($i));

//產(chǎn)生隨機(jī)幹?jǐn)_(randpix():函數(shù)呼叫)

for($j=0;$j<50;$j )

{

? imagesetpixel($i, mt_rand(0,$width),mt_rand(0,$height) ,randpix($i));


}

//寫字

for($j=0;$j<$num;$j )

{


? ? $x=floor($width/$num)*$j 2;

? ? $y=mt_rand(3,$height-15);

? ??

? ? imagechar($i,5,$x,$y,$string[$j], randpix($i));

}

#//圖片格式

##? ? $fuc ='image'.$type;


? ? $have='cotent-type:image'.$type;

? ? if(function_exists($fuc))

? ? {

? ? ? ? header($have);

? ? ? ? $fuc($i);

? ? }

? ? else

#o? ? }

?#? else

#?

?#? ? ? ? echo '不支持圖片類型';

? ? }

? ? imagedestroy($i);

? ? return $string;

}

??

//背景顏色函數(shù)功能模組?

? ?function randbg($i)

? ?{

#? ? ? ?return imagecolorallocate($i,mt_rand5) mt_rand(135,255),mt_rand(135,255));

? ? ? ?

? ?}

//幹?jǐn)_元素或字元顏色函數(shù)功能模組?

? ?function randpix($i)

? ?{

##? ? ? randpix($i)

? ?{

##? ? ? color?return image,colorallocate($i,mt_rand(0,135) color?return image,colorallocate($i,mt_rand(0,135) color?return_mtallocate($i,mt_rand(0,135) color?return_mt. (0,135),mt_rand(0,135));

? ? ? ?

? ?} ??

#?>

################?>######################?>######################?>#############
phpcn_u53259
phpcn_u53259

全部回覆(2)
路過
這是個(gè)驗(yàn)證碼類,你可以參考一下
<?php

class?Captcha
{
????private?$width;
????private?$height;
????private?$codeNum;
????private?$code;
????private?$im;

????function?__construct($width=80,?$height=20,?$codeNum=4)
????{
????????$this->width?=?$width;
????????$this->height?=?$height;
????????$this->codeNum?=?$codeNum;
????}

????function?showImg()
????{
????????//創(chuàng)建圖片
????????$this->createImg();
????????//設(shè)置干擾元素
????????$this->setDisturb();
????????//設(shè)置驗(yàn)證碼
????????$this->setCaptcha();
????????//輸出圖片
????????$this->outputImg();
????}

????function?getCaptcha()
????{
????????return?$this->code;
????}

????private?function?createImg()
????{
????????$this->im?=?imagecreatetruecolor($this->width,?$this->height);
????????$bgColor?=?imagecolorallocate($this->im,?0,?0,?0);
????????imagefill($this->im,?0,?0,?$bgColor);
????}

????private?function?setDisturb()
????{
????????$area?=?($this->width?*?$this->height)?/?20;
????????$disturbNum?=?($area?>?250)???250?:?$area;
????????//加入點(diǎn)干擾
????????for?($i?=?0;?$i?<?$disturbNum;?$i++)?{
????????????$color?=?imagecolorallocate($this->im,?rand(0,?255),?rand(0,?255),?rand(0,?255));
????????????imagesetpixel($this->im,?rand(1,?$this->width?-?2),?rand(1,?$this->height?-?2),?$color);
????????}
????????//加入弧線
????????for?($i?=?0;?$i?<=?5;?$i++)?{
????????????$color?=?imagecolorallocate($this->im,?rand(128,?255),?rand(125,?255),?rand(100,?255));
????????????imagearc($this->im,?rand(0,?$this->width),?rand(0,?$this->height),?rand(30,?300),?rand(20,?200),?50,?30,?$color);
????????}
????}

????private?function?createCode()
????{
????????$str?=?"23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ";

????????for?($i?=?0;?$i?<?$this->codeNum;?$i++)?{
????????????$this->code?.=?$str{rand(0,?strlen($str)?-?1)};
????????}
????}

????private?function?setCaptcha()
????{
????????$this->createCode();

????????for?($i?=?0;?$i?<?$this->codeNum;?$i++)?{
????????????$color?=?imagecolorallocate($this->im,?rand(50,?250),?rand(100,?250),?rand(128,?250));
????????????$size?=?rand(floor($this->height?/?5),?floor($this->height?/?3));
????????????$x?=?floor($this->width?/?$this->codeNum)?*?$i?+?5;
????????????$y?=?rand(0,?$this->height?-?20);
????????????imagechar($this->im,?$size,?$x,?$y,?$this->code{$i},?$color);
????????}
????}

????private?function?outputImg()
????{
????????if?(imagetypes()?&?IMG_JPG)?{
????????????header('Content-type:image/jpeg');
????????????imagejpeg($this->im);
????????}?elseif?(imagetypes()?&?IMG_GIF)?{
????????????header('Content-type:?image/gif');
????????????imagegif($this->im);
????????}?elseif?(imagetype()?&?IMG_PNG)?{
????????????header('Content-type:?image/png');
????????????imagepng($this->im);
????????}?else?{
????????????die("Don't?support?image?type!");
????????}
????}

}

//?這樣調(diào)用?新建文件
<?php
require_once?'captcha.class.php';

$captcha?=?new?Captcha(80,30,4);

$captcha->showImg();


#
路過

貼出報(bào)錯(cuò)訊息啊,誰有功夫看你程式碼? ? ?

  • 回覆 就是亂碼了,什麼報(bào)錯(cuò)都沒有。應(yīng)該是//圖片格式//出錯(cuò)了。
    phpcn_u53259 作者 2017-11-07 17:38:05
  • 回覆 早就試過了,一樣亂碼
    phpcn_u53259 作者 2017-11-08 09:42:13
  • 回覆 檔案名稱?這裡面沒有寫檔名進(jìn)去的語句?
    phpcn_u53259 作者 2017-11-08 10:29:07
  • 回覆 好的,謝謝~
    phpcn_u53259 作者 2017-11-08 14:05:56
  • 回覆 哦,你加個(gè)header頭聲明utf-8 試試吧
    路過 作者 2017-11-08 08:19:59
  • 回覆 看看你的檔名是不是錯(cuò)了
    路過 作者 2017-11-08 10:21:41
  • 回覆 你代碼有問題
    路過 作者 2017-11-08 13:45:45
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板