php 繪製驗證碼 示例

2022-05-03 04:48:10 字數 1375 閱讀 9194

1

<?php

2header("content-type:image/jpeg");34

session_start();//

開啟session56

//寬高 字型大小

7$width=120;

8$height=40;

9$fontsize=20;

1011

//給畫布寬高

12$img=imagecreatetruecolor($width,$height

);13

14//

畫布背景色

15$bgcolor=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));

1617

//畫布邊框背景

18$bordercolor=imagecolorallocate($img,rand(0,155),rand(0,155),rand(0,155));

1920

//內容字型顏色

21$fontcolor=imagecolorallocate($img,rand(30,100),rand(30,100),rand(30,100));

2223

//填充背景色

24 imagefill($img,0,0,$bgcolor

);25

26//

填充邊框

27 imagerectangle($img,0,0,$width-1,$height-1,$bordercolor

);28

29//

干擾點30

for($a=0;$a

<100;$a++)

3334

//建立陣列

35$shuzi=range(0,9);

3637

//隨機數

38$suiji=$shuzi[rand(0,count($shuzi)-1)].$shuzi[rand(0,count($shuzi)-1)]

39 .$shuzi[rand(0,count($shuzi)-1)].$shuzi[rand(0,count($shuzi)-1)];

4041

//輸出內容

42 imagettftext($img,$fontsize,rand(-5,5),rand(15,25),rand(28,33),$fontcolor,'ziti.ttf',$suiji);$_session['yzm_b']=$suiji;43

44//

獲取『驗證碼輸入框的內容』

4546

4748

//輸出畫布

49 imagejpeg($img

);50 ?>

PHP驗證碼應用,示例

近日試著用php做了乙個驗證碼程式,示例如下 一 準備乙個展示並提交驗證碼的頁面 header content type text html charset utf 8 開啟session session start 驗證碼 二 以下是驗證碼生成頁面,該頁面在第一頁面中被 header conten...

繪製驗證碼

public partial class validatecode validatebase 生成驗證碼 private string createvalidatecode base.strvalidate validatecode 儲存驗證碼 return validatecode 影象背景 pr...

驗證碼繪製

驗證碼繪製 1.產生驗證碼字串 使用ascii碼和sprintf函式生成驗證碼字串 ascii碼對應字元如下 數字 48 57 小寫字母 97 122 大寫字母 65 90 sprintf c ascii 將ascii碼轉為對應字元2.繪製驗證碼 繪製步驟 1 建立畫布 2 建立畫筆 3 填充背景色...