求路過的大佬解惑,變量未定義問題
<!-- 與圖片相關的核心函數 -->
<?php
// ini_set("error_reporting","E_ALL & ~E_NOTICE");
require_once 'string.func.php';
// 通過GD庫做驗證碼
function verifyImage($type=1,$length=4,$pixel=0,$line=0,$sess_name="verify"){
? ? // 創建一個畫布
? ? $width = 80;
? ? $height = 28;
? ? $image = imagecreatetruecolor($width, $height);
? ? // 創建一個白色
? ? $white = imagecolorallocate($image, 255, 255, 255);
? ? // 創建畫筆的顏色
? ? $black = imagecolorallocate($image, 0, 0, 0);
? ? // 用填充矩形填充畫布($image, 1,1[畫布的起始點], $white[白色填充畫布])
? ? imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $white);
? ? //? ?$type = 1; 防到參數中
? ? //? ?$length = 4;
? ? $chars = buildRandomString($type, $length); /* 可以設置 類型和長度 */
? ? //? ?$sess_name = "verify";
? ? $_SESSION[$sess_name] = $chars; /* 生成的驗證碼放在_SESSION中 */
? ? for ($i = 0; $i < $length; $i ++) {
? ? ? ? $size = mt_rand(14, 18);
? ? ? ? $angle = mt_rand(- 15, 15);
? ? ? ? $x = 5 + $i * $size;
? ? ? ? $y = mt_rand(20, 26);
? ? ? ? $fontfile = "../fonts/".$fontfiles[mt_rand(0, count($fontfiles) - 1)];
? ? ? ? $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
? ? ? ? $text = substr($chars, $i, 1);
? ? ? ? imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text);
? ? }
? ? // 設置點干擾元素
? ? // $pixel = 0; 默認為0
? ? if ($pixel) { /* 如果設置為真,則開始執行 */
? ? ? ? for ($i; $i < $pixel; $i ++) {
? ? ? ? ? ? imagesetpixel($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), $black);
? ? ? ? }
? ? }
? ? // 線干擾元素
? ? // $line = 0;
? ? if ($line) {
? ? ? ? for ($i; $i < $line; $i ++) {
? ? ? ? ? ? $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
? ? ? ? ? ? imageline($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), mt_rand(0, $width - 1), mt_rand(0, $height - 1), $color);
? ? ? ? }
? ? }
? ? // 告訴瀏覽器要顯示的是什么資源
? ? header ( "content-type:image/gif" );
? ? // 顯示創建好的畫布
? ? imagegif($image);
? ? // 銷毀畫布資源
? ? imagedestroy($image);
}
verifyImage();
2018-12-04
對比了老師的源碼,加了一句,大部分錯誤解決了,不知道是我太粗心沒看見這一句,還是到目前為止老師也沒加這句,不得而知