国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php生成圖片驗證碼

2020-03-22 20:17:58
字體:
來源:轉載
供稿:網友
$image = imagecreatetruecolor(100, 30); //創建畫布 $imagecolor = imagecolorallocate($image, 255, 255, 255); //背景色 imagefill($image, 0, 0, $imagecolor); //填充背景色 for($i=0;$i $i++ ){ //循環4位數 $fontsize = 6; $fontcolor = imagecolorallocate($image, rand(0, 200), rand(0, 200), rand(0, 200)); $fontcontent = rand(0, 9); $x = $i*100/4 + rand(5, 15); $y = rand(5, 10); imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor); for($i=0;$i $i++ ){ //循環 添加干擾點 $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200)); $x = rand(1, 99); $y = rand(1, 29); imagesetpixel($image, $x, $y, $pointcolor); for($i=0;$i $i++){ //循環 添加干擾線 $linecolor = imagecolorallocate($image, rand(100, 250), rand(100, 250), rand(100, 250)); $x1 = rand(1, 25); $x2 = rand(50, 75); $y1 = rand(1, 15); $y2 = rand(15, 25); imageline($image, $x1, $y1, $x2, $y2, $linecolor); header("content-type:image/png"); imagepng($image); imagedestroy($image); 再給大家分享一個可以生成中文驗證碼//1.qi啟用gd庫GD庫提供了一系列用來處理圖片的API,使用GD庫可以處理圖片,或者生成圖片。 // 在網站上GD庫通常用來生成縮略圖或者用來對圖片加水印或者對網站數據生成報表。session_start();// 把GBK編碼的html' target='_blank'>字符串轉換成UTF-8字符串,第一個參數之所以寫GBK,是因為本php文件在主機中存儲的編碼是GBK編碼// UTF-8編碼瀏覽器普遍支持,通用性強,這里就轉換成UTF-8$str = iconv("GBK", "utf-8", "蕓蕓眾生綠水青山名勝古跡敞開心胸便會云蒸霞蔚快樂將永遠伴隨著你");if(!is_string($str) || !mb_check_encoding($str,"utf-8")) exit("不是字符串或者不是utf-8");$zhongwenku_size;// 按UTF-8編碼方式獲取字符串的長度$zhongwenku_size = mb_strlen($str,"UTF-8");// 把上述字符導入數組中$zhongwenku = array();for( $i=0; $i $zhongwenku_size; $i++) $zhongwenku[$i] = mb_substr($str, $i,1,"UTF-8");$result = "";// 圖片上要寫入的四個字符for($i=0; $i $i++) switch (rand(0, 1)) case 0: $result.=$zhongwenku[rand(0, $zhongwenku_size-1)]; break; case 1: $result.=dechex(rand(0,15)); break;$_SESSION["check"] = $result;// 創建一個真彩圖片 寬100,高30$img = imagecreatetruecolor(100, 30);// 分配背景顏色$bg = imagecolorallocate($img, 0, 0, 0);// 分配文字顏色$te = imagecolorallocate($img, 255,255,255);// 在圖片上寫字符串//imagestring($img, rand(3,8), rand(1,70), rand(1,10), $result, $te);// 在圖片上根據載入字體可以寫出特殊字體imagettftext($img, 13, rand(2, 9), 20 ,20, $te, "MSYH.TTF",$result);$_SESSION["check"] = $result;for($i=0; $i $i++)// $t = imagecolorallocate($img, rand(0, 255),rand(0, 255),rand(0, 255)); // 畫線 imageline($img, 0, rand(0, 20), rand(70,100), rand(0, 20), $te); $t = imagecolorallocate($img, rand(0, 255),rand(0, 255),rand(0, 255));// 為圖片添加噪點for($i=0; $i $i++) imagesetpixel($img, rand(1, 100), rand(1, 30), $t);// 發送http頭信息 指定本次發送的是image中的jpegheader("Content-type: image/jpeg");// 輸出jpeg圖片至瀏覽器imagejpeg($img); 再來一個實例吧session_start();function random($len) { $srcstr = "1a2s3d4f5g6hj8k9qwertyupzxcvbnm"; mt_srand(); $strs = ""; for ($i = 0; $i $len; $i++) { $strs .= $srcstr[mt_rand(0, 30)]; return $strs;//隨機生成的字符串$str = random(4); //驗證碼圖片的寬度$width = 50; //驗證碼圖片的高度$height = 25; //聲明需要創建的圖層的圖片格式@ header("Content-Type:image/png");//創建一個圖層$im = imagecreate($width, $height);//背景色$back = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);//模糊點顏色$pix = imagecolorallocate($im, 187, 230, 247);//字體色$font = imagecolorallocate($im, 41, 163, 238);//繪模糊作用的點mt_srand();for ($i = 0; $i 1000; $i++) { imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pix);//輸出字符imagestring($im, 5, 7, 5, $str, $font);//輸出矩形imagerectangle($im, 0, 0, $width -1, $height -1, $font);//輸出圖片imagepng($im);imagedestroy($im);$str = md5($str);//選擇 cookie//SetCookie("verification", $str, time() + 7200, "/");//選擇 Session$_SESSION["verification"] = $str;接下來只要在頁面中調用就可以了:
img id="checkpic" src='/images/checkcode.php' / 如果想實現 "看不清?換一張" 效果,添加如下 JS 到頁面中
function changing(){ document.getElementById('checkpic').src="/images/checkcode.php "+Math.random();} 以上所述就是本文的全部內容了,希望大家能夠喜歡。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴海县| 德江县| 宝鸡市| 博客| 邓州市| 西和县| 苏尼特右旗| 威宁| 霸州市| 德保县| 锦州市| 寻乌县| 阜康市| 石林| 南川市| 天门市| 沁源县| 临西县| 吉木萨尔县| 柳河县| 呼图壁县| 柞水县| 始兴县| 个旧市| 庆云县| 陕西省| 东丰县| 朝阳县| 富裕县| 崇仁县| 洛浦县| 都兰县| 威宁| 泰安市| 沅陵县| 调兵山市| 宁海县| 镇沅| 循化| 佛教| 印江|