《PHP學習:利用PHP繪圖函數實現簡單驗證碼功能的方法》要點:
本文介紹了PHP學習:利用PHP繪圖函數實現簡單驗證碼功能的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP實例index.php
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);
PHP實例login.php
PHP實例
請輸入驗證碼:<img src="index.php" onclick="this.src='index.php?a=+random()'">
PHP實例以上就是小編為大家帶來的利用PHP繪圖函數實現簡單驗證碼功能的方法全部內容了,希望大家多多支持維易PHP~
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/3017.html