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繪圖函數實現簡單驗證碼功能的方法全部內容了,希望大家多多支持VeVb武林網~
新聞熱點
疑難解答
圖片精選