程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 利用PHP繪圖函數實現簡單驗證碼功能的方法

利用PHP繪圖函數實現簡單驗證碼功能的方法

編輯:PHP綜合

index.php

<?php
//===================================》》使用繪圖技術繪制驗證碼

//1.隨機產生4個隨機數
$checkCode="";
for ($i=0;$i<4;$i++){
$checkCode.=dechex(rand(1, 15));// decheck()十進制轉換為十六進制,即驗證碼上要顯示的數字
}

//2.存入列
session_start();
$_SESSION['checkCode']=$checkCode;

//3.創建畫布
$image1=imagecreatetruecolor(100, 30);

//制造干擾,創建20條弧線
for ($j=0;$j<30;$j++){
imagearc($image1, rand(0, 100), rand(0, 30), rand(0, 100), rand(0, 30), rand(0, 360), rand(0, 360), imagecolorallocate($image1, rand(0, 155), rand(0, 255), rand(0, 255)));
}

//3.創建字體顏色,將字粘貼上去
$white=imagecolorallocate($image1, 255, 255, 255);
imagestring($image1, rand(2, 5), rand(5, 70), rand(2, 15), $checkCode, $white);

//5.輸出圖像或保存
header("content-type:image/png");
imagepng($image1);

//6.釋放資源
imagedestroy($image1);

login.php

請輸入驗證碼:<img src="index.php" onclick="this.src='index.php?a=+random()'">

以上就是小編為大家帶來的利用PHP繪圖函數實現簡單驗證碼功能的方法全部內容了,希望大家多多支持~

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved