PHP全棧學習筆記26
摘要:
php 驗證碼
image.png
<?php
/*
*@Author: 達叔小生
**/
header("Content-type:image/png");// 傳送頭部資訊,生成png圖片檔案
$str = ...
php 驗證碼

image.png
<?php /* *@Author: 達叔小生 **/ header("Content-type:image/png");// 傳送頭部資訊,生成png圖片檔案 $str = 'qwertyuiopasdfghjklzxcvbnm1234567890'; $l = strlen($str);//得到字串的長度 $authnum = ''; for($i=1;$i<=4;$i++){ $num = rand(0,$i-1);//每次隨機抽取一位數字 $authnum.=$str[$num];//將通過數字得來的字串連起來 } srand((double)microtime()*1000000); $im = imagecreate(50,20); $black = imagecolorallocate($im,0,0,0); $white = imagecolorallocate($im,255,255,255); $gray = imagecolorallocate($im,200,200,200); imagefill($im,68,30,$black); imagestring($im,5,8,2, $authnum, $white); imagepng($im); imagedestroy($im); ?>