兩款產生圖形驗證碼的php代碼_PHP教程

來源:互聯網
上載者:User
驗證碼在php中是經常會用到了,下面我們為你提供了一些關於php驗證碼產生類與程式,直接複製下去就可以直接用的哦,下面看代碼。

驗證碼在php教程中是經常會用到了,下面我們為你提供了一些關於php驗證碼產生類與程式,直接複製下去就可以直接用的哦,下面看代碼。

session_start();
Header("Content-type: image/gif");
class SecurityCode
{
private $codes = '';
function __construct()
{
$code = '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';
$codeArray = explode('-',$code);
shuffle($codeArray);
$this->codes = implode('',array_slice($codeArray,0,4));
}
public function CreateImg()
{
$_SESSION['check_pic'] = $this->codes;
$img = imagecreate(70,25);
imagecolorallocate($img,222,222,222);
$testcolor1 = imagecolorallocate($img,255,0,0);
$testcolor2 = imagecolorallocate($img,51,51,51);
$testcolor3 = imagecolorallocate($img,0,0,255);
$testcolor4 = imagecolorallocate($img,255,0,255);
for ($i = 0; $i < 4; $i++)
{
imagestring($img,rand(5,6),8 + $i * 15,rand(2,8),$this->codes[$i],rand(1,4));
}
imagegif($img);
}
}
$code = new SecurityCode();
$code->CreateImg();
$code = NULL;
?>

代碼二

session_start();
for($i=0; $i<4; $i++){
$rand.= dechex(rand(1,15));
}
$_SESSION[check_pic]=$rand;
//echo $_SESSION[check_pic];
// 設定圖片大小">圖片大小
$im = imagecreatetruecolor(100,30);
// 設定顏色
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,255,255,255);
// 把字串寫在映像左上方
imagestring($im,rand(5,6),rand(25,30),5,$rand,$te);
// 輸出映像
header("Content-type:image/jpeg");
imagejpeg($im);
?>

http://www.bkjia.com/PHPjc/632979.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632979.htmlTechArticle驗證碼在php中是經常會用到了,下面我們為你提供了一些關於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.