php 產生驗證碼

來源:互聯網
上載者:User

標籤:驗證碼

create_code.php

<?php

session_start();

//產生驗證碼圖片

header("Content-type: image/png");

// 全數字

$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g";      //要顯示的字元,可自己進行增刪

$list = explode(",", $str);

$cmax = count($list) - 1;

$verifyCode = ‘‘;

for ( $i=0; $i < 5; $i++ ){

      $randnum = mt_rand(0, $cmax);

      $verifyCode .= $list[$randnum];           //取出字元,組合成為我們要的驗證碼字元

}

$_SESSION[‘code‘] = $verifyCode;        //將字元放入SESSION中

 

$im = imagecreate(58,28);    //產生圖片

$black = imagecolorallocate($im, 0,0,0);     //此條及以下三條為設定的顏色

$white = imagecolorallocate($im, 255,255,255);

$gray = imagecolorallocate($im, 200,200,200);

$red = imagecolorallocate($im, 255, 0, 0);

imagefill($im,0,0,$white);     //給圖片填充顏色

 

//將驗證碼繪入圖片

imagestring($im, 5, 10, 8, $verifyCode, $black);    //將驗證碼寫入到圖片中

 

for($i=0;$i<50;$i++)  //加入幹擾象素

{

     imagesetpixel($im, rand()p , rand()0 , $black);    //加入點狀幹擾素

     imagesetpixel($im, rand()p , rand()0 , $red);

     imagesetpixel($im, rand()p , rand()0 , $gray);

     //imagearc($im, rand()p, rand()p, 20, 20, 75, 170, $black);    //加入弧線狀幹擾素

     //imageline($im, rand()p, rand()p, rand()p, rand()p, $red);    //加入線條狀幹擾素

}

imagepng($im);

imagedestroy($im);

?>


php 產生驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.